我正在使用以下代码建立http连接:
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = client.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)
我想从响应对象中读取一个bytearray.
我该怎么办?
您可以使用以下方法直接读取字节数组:EntityUtils.toByteArray
例
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("localhost:8080/myurl");
HttpResponse response = client.execute(get);
byte[] content = EntityUtils.toByteArray(response.getEntity());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9014 次 |
| 最近记录: |