Java Network Programming from entry to mastery (3): Why can't I access a website directly through an IP address?

Source: Internet
Author: User

In the article "four static methods for creating InetAddress objects", get the four IP addresses corresponding to through getAllByName. Theoretically, entering one of the four IP addresses in the address bar of IE (or another Web browser, such as Firefox) may access For example, enter http: // However, IE returns an error message. After you enter the other three IP addresses, the same error message is returned.

This error does not mean that the webpage does not find an error (HTTP status code: 404), but rejects the access error (HTTP status code: 403 ). When you enter a in the address bar, you can still access this website. From the above indications, this is not a client issue, but a server limit.

There is a Host field in the request header of the HTTP protocol (which will be detailed in the next chapter). Generally, when accessing the server through the, the Host value is For http: //, the Host value is Therefore, we can infer that the server can detect the Host field to prevent clients from directly using IP addresses for access. There are many websites such as and Some websites do not use IP addresses for access, but when using IP addresses to access the website, the IP addresses are relocated to the corresponding domain names. If you enter http: //, it will be relocated to html "> callback.

The ping Command can also be used to obtain the IP address of a domain name. If the domain name is bound with an IP address, DNS returns an IP address at random. For example, enter the following command in the console:

Returned results

Reply from bytes = 32 time = 31 ms TTL = 48
Reply from bytes = 32 time = 35 ms TTL = 48
The IP address in the returned result above is the third IP address obtained by MyInetAddress3 in Test 1 in "four static methods for creating InetAddress objects.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.