Solution: It was a mistake on my side.
The right way is response.body().string() other than response.body.toString()
Im using Jetty servlet, the URL ishttp://172.16.10.126:8789/test/path/jsonpage
, every time request this URL it will return
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
It shows up when type the url into a browser, unfortunately it shows kind of memory address other than the json string when I request with Okhttp
.
TestActivity﹕ com.squareup.okhttp.internal.http.RealResponseBody@537a7f84
The Okhttp code Im using:
OkHttpClient client = new OkHttpClient();
String run(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
Can anyone helpe?