PHP Get a faraway file

Source: Internet
Author: User
PHP Get remote Files
if (! ( $contents =file_get_contents (' HTTP://FINANCE.YAHOO.COM/D/QUOTES.CSV?S=AMZN&E=.CSV&F=SLLDLTLCLOHGV ')) {
Die (' fail to open Yahoo ');
};
Echo $contents;


Why the average refresh of 3-4 is only one success, the other will appear a warning, prompting HTTP request failed!


------Solution--------------------
C + + code
Bart Friederichs 16-apr-2012 12:17file_get_contents can do-a POST, create a context for that first: $opts = Array (' http ' =&  Gt      Array (' method ' = ' + ' POST ', ' header ' = ' content-type:text/xml\r\n '. "Authorization:basic". Base64_encode ("$https _user: $https _password"). "                        \ r \ n ", ' content ' = $body, ' timeout ' = 60)); $context = Stream_context_create ($opts); $url = ' https://'. $https _server; $result = File_get_contents ($url, False, $ Context,-1, 40000);pp Eregrina 21-dec-2011 11:30for Those have this problem when trying to get_file_contents (URL): Warnin  G:file_get_contents (URL): Failed to open stream:http request failed! In the XX on line yyif you is behind a SonicWall firewall, read this:https://bugs.php.net/bug.php?id=40197 (This little line:  Uncheck a box in the internal settings of the firewall labled ' enforce Host Tag Search with for CFS ' apparently by default SonicWall blocks any HTTP request without a "Host:" header, which are the caseIn the PHP get_file_contents (URL) implementation. This is what, if you try to get the same URL from the same machine with CURL our wget, it works. I hope this'll be useful to someone, it took me hours to find out:) godwraith01 at yahoo dot com 11-oct-2011 04:16i expe Rienced a problem in using the hostnames instead straight IP with some server destinations. If I use file_get_contents ("Www.jbossServer.example/app1",...) I'll get a ' Invalid hostname ' from the server I ' m calling. This is because file_get_contents probably would rewrite your request after getting the IP, obtaining the same thing As:fi Le_get_contents ("Xxx.yyy.www.zzz/app1",...) And you know that many servers would deny you access if you go through IP addressing in the request. With CURL This problem doesn ' t exists.  it resolves the hostname leaving the request as you set it up, so the server was not rude in response.
  • 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.