import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; public void test() throws ClientProtocolException, IOException{
RequestConfig config = RequestConfig.custom()
.setConnectionRequestTimeout(40000).setConnectTimeout(40000)
.setSocketTimeout(40000).build(); HttpGet httpGet = new HttpGet("http://iphone.myzaker.com/zaker/article_telecom.php?app_id=1&for=delong"); httpGet.setConfig(config); CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(null).build();//设置进去 HttpClients.createDefault(); CloseableHttpResponse response = null;
response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
// 开始读取内容
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
}

inputstream输出为String的更多相关文章

  1. Java 把 InputStream 转换成 String 的几种方法

    我们在 Java 中经常会碰到如何把 InputStream 转换成 String 的情形,比如从文件或网络得到一个 InputStream,需要转换成字符串输出或赋给别的变量. 未真正关注这个问题之 ...

  2. Java 里把 InputStream 转换成 String 的几种方法

    我们在 Java 中经常会碰到如何把 InputStream 转换成 String 的情形,比如从文件或网络得到一个 InputStream,需要转换成字符串输出或赋给别的变量. 未真正关注这个问题之 ...

  3. 使用TRACE时 输出 _CrtDbgReport: String too long or IO Error

    在VS2010中使用MFC,使用UNICODE 调用TRACE,输出_CrtDbgReport: String too long or IO Error 可尝试使用OutputDebugString函 ...

  4. Java中将InputStream读取为String, 各种方法的性能对比

    如下, 一共存在11种实现方式及其对应的性能测试结果: 1. 使用IOUtils.toString (Apache Utils) String result = IOUtils.toString(in ...

  5. InputStream转化为String

    参考:https://blog.csdn.net/lmy86263/article/details/60479350 eg:  InputStream in = PropertiesUtils.cla ...

  6. inputStream输入流转为String对象(将String对象转为inputStream输入流)

    不得不说org.apache.commons包下有很多实用的工具类. org.apache.commons.io.IOUtils; 要将inputStream输入流转为String对象,只需使用org ...

  7. 使用Scanner将InputStream类型转换成String

    我们在测试项目中经常会遇到这样的情形: 1. 从文件或网络得到一个InputStream,需要转换成String赋值到别的变量做为另一个方法的入参. 2. 从文件或网络得到一个InputStream后 ...

  8. java:OutputStream和InputStream 输出输入流,FileOutputStream,FileInputStream写入读取流

    1.在java中stream代表一种数据流(源),javaio的底层数据元,---(想像成水龙头)2.任何有能力产生数据流(源)的javaio对象就可以看作是一个InputStream对象既然它能产生 ...

  9. 输出一个string的所有排列情况

    问题: 1.加入输入是{a,b,c}; 2.输出abc,acb,bac,bca,cab,cba; 代码描述: 1.递归遍历所有情况 2.方法FUN输入为:要排列的字符串char inp[];inp[] ...

随机推荐

  1. 自己动手写CPU之第七阶段(6)——乘累加指令实现思路

    将陆续上传本人写的新书<自己动手写CPU>.今天是第29篇.我尽量每周四篇 亚马逊的销售地址例如以下,欢迎大家围观呵! http://www.amazon.cn/dp/b00mqkrlg8 ...

  2. Android自己定义View之组合控件 ---- LED数字时钟

    先上图 LEDView效果如图所看到的. 之前看到一篇博客使用两个TextView实现了该效果.于是我想用自己定义控件的方式实现一个LEDView.使用时就可以直接使用该控件. 採用组合控件的方式,将 ...

  3. Redis命令-HyperLogLog

    HyperLogLog数据结构简单介绍 能够看http://www.cnblogs.com/ysuzhaixuefei/p/4052110.html  博客,介绍的相对照较清晰. HyperLogLo ...

  4. HDU 5493 Queue 树状数组+二分

    Queue Problem Description N people numbered from 1 to N are waiting in a bank for service. They all ...

  5. Android中添加自己的模块 【转】

    本文转载自:http://wallage.blog.163.com/blog/static/17389624201021791333695/ 转:http://blog.csdn.net/yili_x ...

  6. Unable to access the IIS metabase

    https://stackoverflow.com/questions/12859891/error-unable-to-access-the-iis-metabase 解决方法1 On Window ...

  7. ES TransportClient demo

    import java.net.InetAddress; import java.net.UnknownHostException; import org.elasticsearch.action.b ...

  8. jQuery进度条设置

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv="con ...

  9. Memcache使用场景

    session //php文件中 ini_set("session.save_handler", "memcache"); ini_set("sess ...

  10. Fildder 4接口测试工具Post请求方式