简体   繁体   English

HTTPClient给出404而没有www作为网址

[英]HTTPClient gives 404 without www for a url

I am using apache HTTPClient 4.2. 我正在使用apache HTTPClient 4.2。 I used this below code to get the HTTP status code. 我使用以下代码获取HTTP状态代码。 It gives me 404 . 它给我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();
        }

But if Change the url to this(I have added www to url), http://www.michaelkimsal.com/blog/hosted-solr-or-lucene-service/comment-page-1/#comment-604253 it gives me 200 . 但是,如果将网址更改为此(我在网址中添加了www),则http://www.michaelkimsal.com/blog/hosted-solr-or-lucene-service/comment-page-1/#comment-604253200 What may be the reason for this behavior? 发生这种现象的原因可能是什么? Please some one help come out of this problem. 请从这个问题中得到一些帮助。

http://michaelkimsal.com is not valid domain in your case, browser is intelligent in some case that automatically handle such case, you should use proper domain with www. http://michaelkimsal.com在您的情况下不是有效的域,浏览器在某些情况下是智能的,可以自动处理这种情况,您应该在www上使用适当的域。

Edit please check this link of serverault and wiki 编辑,请检查serverault和Wiki的 链接

It works for google because it has done dns resolution setup for that. 它适用于Google,因为它已经为此完成了DNS解析设置。 You can also setup aliases 您还可以设置别名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM