我想從回復中讀取狀態和短信。我該怎么做 ?我嘗試使用這段代碼,但它運行不完美new Thread(new Runnable() {? ? ? ? URL url = null;? ? ? ? int code;? ? ? ? @Override? ? ? ? public void run() {? ? ? ? ? ? try {? ? ? ? ? ? ? ? url = new URL("http://domscanner.ru/api/poll/login?phone=79232893050");? ? ? ? ? ? ? ? OkHttpClient client = new OkHttpClient();? ? ? ? ? ? ? ? Request request = new Request.Builder()? ? ? ? ? ? ? ? ? ? ? ? .url(url)? ? ? ? ? ? ? ? ? ? ? ? .build();? ? ? ? ? ? ? ? Call call = client.newCall(request);? ? ? ? ? ? ? ? Response response = call.execute();? ? ? ? ? ? ? ? code = response.code();? ? ? ? ? ? ? ? if (!response.isSuccessful()) {? ? ? ? ? ? ? ? ? ? code = response.code();? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? String results;? ? ? ? ? ? ? ? Log.i("TEST", "code " + code);? ? ? ? ? ? ? ? if(code == 200) {? ? ? ? ? ? ? ? ? ? results = response.body().toString();? ? ? ? ? ? ? ? } else {? ? ? ? ? ? ? ? ? ? results = "nothing";? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? Log.i("TEST ", "result " + results);? ? ? ? ? ? } catch (MalformedURLException e) {? ? ? ? ? ? ? ? e.printStackTrace();? ? ? ? ? ? } catch (IOException e) {? ? ? ? ? ? ? ? e.printStackTrace();? ? ? ? ? ? }? ? ? ? }? ? }).start();在日志代碼中200結果okhttp3.internal.http.RealResponseBody@90b58f4
1 回答

墨色風雨
TA貢獻1853條經驗 獲得超6個贊
更改 if else 語句如下:
if(code == 200) {
results = response.body().string();
} else {
results = "nothing";
}
添加回答
舉報
0/150
提交
取消