Curl providing 503 services unavailable in response

My url "www.example.com" works in a browser, but when I get a response through the curl of the URL "www.example.com", I get a message about the unavailability of the 503 service.

I used the following code:

 $url = 'http://www.example.com';
   $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, $url);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
    curl_setopt($curl_handle, CURLOPT_TIMEOUT, 0);
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);  
    curl_setopt($curl_handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
    $JsonResponse = curl_exec($curl_handle);
    $http_code = curl_getinfo($curl_handle);
    print_r($http_code);die;
+5
source share
1 answer

I am sure that the remote server requires certain HTTP headers (like cookies), like a session token or language preferences.

You need to analyze the HTTP traffic sent from your browser to the remote server and find the necessary HTTP headers yourself. I recommend a tool like Fiddler .

Example:

GET / HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: foo=bar
Connection: keep-alive

, , cookie foo, , , 503 400 , . cookie cURL, , .

0

Source: https://habr.com/ru/post/1526876/


All Articles