我是Android的新手,我得到服务响应null但是服务URL在浏览器中运行正常。当我运行我的应用程序屏幕时显示空白,没有数据来自我做错的服务,请帮助我。
我的片段:
public class OKHttpRequest {
OkHttpClient client = new OkHttpClient();
public static final MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
public String doGetRequest(String url) throws IOException {
try {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
catch (Exception e){
e.printStackTrace();
}
return null;
}
String doPostRequest(String url, String json) throws IOException {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}}
OKHttp类:
char *myArray[] = { "aaaaaa", "ccccc", "bbbbbb", "111111" };
答案 0 :(得分:0)
答案 1 :(得分:0)
此外,您可以使用Rest-client(添加Chrome和Firefox),如果正常使用HttpsURLConnection,它可能会对您有所帮助。