Search code examples
phpcurlphp-curl

Get http request from server with php curl or something else, using port


I have a server, with 3rd party API installed, located: http://65.21.1.13:3000/. When I open it in browser, I receive the answer - Service start!, meaning that the service is working. I successfully receive this answer using android java or Visual c++ MFC. But when I'm trying to open this site using PHP (curl or file_get_contents) - I receive an error. I tried to add headers, flags and other - my curl_exec always returns false. Is there solution, to get proper answer from server using PHP? One of the curl tries below:

$url = 'http://65.21.1.13';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT ,3000); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$headers = [
    'X-Apple-Tz: 0',
    'X-Apple-Store-Front: 143444,12',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding: gzip, deflate',
    'Accept-Language: en-US,en;q=0.5',
    'Cache-Control: no-cache',
    'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
    'Host: www.example.com',
    'Referer: http://www.example.com/index.php', //Your referrer address
    'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
    'X-MicrosoftAjax: Delta=true'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
var_dump($result);

Solution

  • The answer was very simple. The 3000 port was blocked on PHP machine by firewall. Sorry to bother you.