一.原生OKHttp的Get和Post请求
1.OKHttp_GET 请求
class="brush:java;gutter:true;">private String get(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
2.OKHttp_POST 请求
private String post(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库-okhttp-utils