我想从回复中读取状态和短信。我该怎么做 ?我尝试使用这段代码,但它运行不完美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
提交
取消