简体   繁体   中英

HTTPClient gives 404 without www for a url

I am using apache HTTPClient 4.2. I used this below code to get the HTTP status code. It gives me 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 . 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.

Edit please check this link of serverault and wiki

It works for google because it has done dns resolution setup for that. You can also setup aliases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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