【转】关于HttpClient,HttpURLConnection,OkHttp的用法整理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39403545/article/details/83033308

1 HttpClient入门实例

https://blog.csdn.net/qq_39403545/article/details/83033276

 

2 HttpURLConnection入门实例

https://blog.csdn.net/fightingXia/article/details/71775516

其中文章提到的is2String(inputStream)读取响应结果,可参考如下写法

// 得到响应流
InputStream is = connection.getInputStream();
// 将响应流转换成字符串
byte[] buffer = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int len = 0; (len = is.read(buffer)) > 0;) {
    baos.write(buffer, 0, len);
}
String result = new String(baos.toByteArray(), "utf-8");
System.out.println(result);

 

3 OkHttpClient入门实例

https://www.jianshu.com/p/1873287eed87

展开阅读全文

没有更多推荐了,返回首页