【发布时间】:2015-07-28 18:24:58
【问题描述】:
我在我的项目中使用 Apache httpclient 和 httpcore 来实现 HTTP 请求。 最近发现这个问题:我有这个body的方法
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(URL);
CloseableHttpResponse response = httpclient.execute(httpGet);
Header[] h = response.getAllHeaders();
for (int i = 0; i < h.length; i++) {
System.out.println(h[i].getName());
}
System.out.println(response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
System.out.println(entity.getContentLength());
org.jsoup.nodes.Document doc = Jsoup
.parse(convertStreamToString(content));
System.out.println(convertStreamToString(content));
EntityUtils.consume(entity);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
具有有效 URL 但内容为空且状态码为 200。
我尝试使用 firefox 插件 RESTClient 和一个具有相同 URL 且没有标头的简单 GET 请求(内容响应不为空)。
还可以使用 firefox 调试器重新发送 Get 请求(这次默认标头已经存在)。
Ps:我显然尝试添加所有标题但什么都没有:(
有人可以帮我处理 Apache 组件吗?
【问题讨论】:
标签: java apache-httpclient-4.x http-request