HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable

后端 未结 2 1629
误落风尘
误落风尘 2021-01-18 20:23

I am using function file_get_contents to get contents from web page. Some website working well but most of them give me this error

failed to open stream: HT         


        
相关标签:
2条回答
  • 2021-01-18 20:38

    With this script all Website think you are a Browser:

    <?php
    $url='http://mywebsite.com'
    $ch = curl_init();
         $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
              curl_setopt($ch, CURLOPT_AUTOREFERER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
    
            curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSLVERSION,CURL_SSLVERSION_DEFAULT);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            $webcontent= curl_exec ($ch);
            $error = curl_error($ch); 
            curl_close ($ch);
    ?>
    
    0 讨论(0)
  • 2021-01-18 20:39

    503 means the functions are working and you're getting a response from the remote server denying you. If you ever tried to cURL google results the same thing happens, because they can detect the user-agent used by file_get_contents and cURL and as a result block those user agents. It's also possible that the server you're accessing from also has it's IP address blackballed for such practices.

    Mainly three common reasons why the commands wouldn't work just like the browser in a remote situation.

    1) The default USER-AGENT has been blocked.
    2) Your server's IP block has been blocked.
    3) Remote host has a proxy detection. 
    
    0 讨论(0)
提交回复
热议问题