Questions about using file () to read URLs

Source: Internet
Author: User
 $buffer = file("http://www.sina.com.cn");  for($i=0;$i
  
   < code="">

读取新浪没问题,
但是读163的话,就提示:
因为您的ISP供应商并没有遵循标准的互联网协议,我们对您的访问作出限制,敬请谅解。 您可以通过以下链接继续访问 www.163.com
而读取豆瓣,就报warning:
Warning: file(http://www.douban.com) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:\wamp\www\1\1.php on line 25
读搜狐就全是乱码
这是怎么回事?

Reply content:

 $buffer = file("http://www.sina.com.cn");  for($i=0;$i
  
    < code="">

读取新浪没问题,
但是读163的话,就提示:
因为您的ISP供应商并没有遵循标准的互联网协议,我们对您的访问作出限制,敬请谅解。 您可以通过以下链接继续访问 www.163.com
而读取豆瓣,就报warning:
Warning: file(http://www.douban.com) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:\wamp\www\1\1.php on line 25
读搜狐就全是乱码
这是怎么回事?

fileHTTP requests that are made using PHP functions are like this

GET / HTTP/1.0HOST: www.douban.com

And that's what the browser is sending.

GET / HTTP/1.1Host: www.douban.comConnection: keep-aliveAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8User-Agent: xxxxxxxxxxxxxxxxxxAccept-Encoding: gzip, deflate, sdchAccept-Language: zh-CN,zh;q=0.8,en;q=0.6

Can the Lord understand it (focusing on the difference in the first line)?

If you still don't understand, please keep looking.

However, if you read 163, you will be advised that your ISP provider is not complying with the standard Internet Protocol and we have limited access to your website. You can continue to access the following links
Www.163.com

163 does not support the HTTP/1.0 protocol, but its server is configured to accept http/1.0 requests, when you use the HTTP 1.0 protocol access, will be 302 jump to Http://www.163.com/special/0077jt/error_ Isp.html, which is the error page that displays the above text

And read the Watercress, reported Warning:Warning:file (http://www.douban.com) [function.file]:
Failed to open Stream:http request failed! http/1.1 403 Forbidden in
C:\wamp\www\1\1.php on line 25

Similarly, watercress does not support http/1.0, treats http/1.0 requests more violently, directly rejects (403) because its server is not configured to enable HTTP1.0

Read Sohu is all garbled

Because Sohu's home page, is the default gzip compression

  • 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.