Java network programming from beginner to Proficient (3): Why can't I access the website directly via IP

Source: Internet
Author: User

In the article "creating four static methods of a InetAddress object", four IP addresses for www.csdn.net are obtained by Getallbyname. Theoretically, any of the four IP addresses entered in the address bar of IE (or other Web browsers, such as Firefox) may access www.csdn.net. such as input http://211.100.26.124. But IE returned an error message. After entering three additional IPs, you will get the same error message.

This error is not a Web page error (HTTP status number: 404), but an Access Denied error (HTTP status number: 403). When you enter http://www.csdn.net in the Address bar, you can still access the site. From the above indications that this is not a client-side problem, but the server has limited it .

The request header in the HTTP protocol (which is explained in detail in the next chapter) has a host field, and the value of host is www.csdn.net when it accesses the server through Http://www.csdn.net. If it is http:// 211.100.26.124, then the value of host is 211.100.26.124. Therefore, we can infer that the Www.csdn.net server prevents clients from using IP directly for access by detecting the host field . There are many websites, such as www.sina.com.cn, www.126.com, and so on. Some Web sites are not restricted to access by IP addresses, but when using IP addresses to access the site, the IP address is relocated to the appropriate domain name. If the input http://141.146.8.66 is relocated to the http://www.oracle.com/index.html, the input http://129.42.60.212 will be relocated to http://www.ibm.com/us/ On

The ping command can also get the IP address of a domain name, and if the domain name is bound to an IP address, DNS will return an IP address randomly. As in the console, enter the following command:

Ping www.csdn.net

return Results

Reply from 211.100.26.122:bytes=32 time=31ms ttl=48 Reply from 211.100.26.122:bytes=32 time=35ms ttl=48

The IP address in the return result above is the third IP address MYINETADDRESS3 in Test 1 in the article "creating four static methods of a InetAddress object".

Java network programming from beginner to Proficient (3): Why can't I access the website directly via IP

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: info-contact@alibabacloud.com 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.