OkHttpClient的使用方法
2018-03-22 14:31
531 查看
参考资料
https://github.com/square/okhttp/wikihttps://github.com/square/okhttp/wiki/Recipes
使用方法
get
// 获取OkHttpClient private final OkHttpClient client = new OkHttpClient(); // 执行方法 public void run() throws Exception { // 建立Builder Request request = new Request.Builder() .url("https://publicobject.com/helloworld.txt") .build(); // 请求 try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); // 获取头部 Headers responseHeaders = response.headers(); // 遍历头部信息 for (int i = 0; i < responseHeaders.size(); i++) { System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i)); } // 获取身体信息 System.out.println(response.body().string()); } }
相关文章推荐
- Android HttpClient基本使用方法
- Apache Common HttpClient七种常用使用方法和注意事项
- Android HttpClient基本使用方法
- 【转载】Android HttpClient基本使用方法
- C++中使用CAtlHttpClient显示网络图片的方法,支持png,bmp,gif图片格式
- Android HttpClient基本使用方法
- C++中使用CAtlHttpClient显示网络图片的方法,支持png,bmp,gif图片格式
- Android HttpClient基本使用方法
- Android HttpClient GET或者POST请求基本使用方法
- Android HttpClient基本使用方法(转)
- Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
- HttpClient 4使用方法的几个例子
- Android HttpClient基本使用方法
- HttpClient使用方法
- 转:Android HttpClient基本使用方法
- 利用HttpClient获得cookie,并在webview中使用的方法
- httpclient 4.0 使用方法
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- Android学习指南之三十:使用URLConnection和HttpClient访问网络的方法
- HttpUtility类,WPF 使用 .net framework 4.0 client profile 不能引用system.web 解决方法(UrlEncode,HtmlEncode)