1

I have the url like this enter link description here

I want to read status and sms from response. How can I do it ? I try to use this code, but it do not work perfect

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();

in log code 200

result

okhttp3.internal.http.RealResponseBody@90b58f4

1 Answer 1

1

change if else statement like below:

if(code == 200) {
    results = response.body().string();
} else {
    results = "nothing";
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.