首页 > Web开发 > 详细

OKHttp

时间:2016-11-03 02:42:56      阅读:262      评论:0      收藏:0      [点我收藏+]

一.原生OKHttp的Get和Post请求

1.OKHttp_GET 请求

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

 

OKHttp

原文:http://www.cnblogs.com/ganchuanpu/p/6021412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!