【发布时间】:2012-08-09 14:21:58
【问题描述】:
我正在使用 apache HTTPClient 4.2。我使用下面的代码来获取 HTTP 状态代码。它给了我404。
DefaultHttpClient client = new DefaultHttpClient();
HttpContext context = new BasicHttpContext();
HttpUriRequest method = new HttpGet("http://michaelkimsal.com/blog/hosted-solr-or-lucene-service/comment-page-1/#comment-604253");
try {
HttpResponse httpResponse = client.execute(method,context);
int status = httpResponse.getStatusLine().getStatusCode();
System.out.println("The status is:"+status);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是如果将 url 更改为此(我已将 www 添加到 url),http://www.michaelkimsal.com/blog/hosted-solr-or-lucene-service/comment-page-1/#comment-604253 它会给我200。这种行为的原因可能是什么?请有人帮忙解决这个问题。
【问题讨论】:
标签: java apache httpclient