0

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);
4
  • cUrl verbose information: * About to connect() to 65.21.1.13 port 3000 (#1) * Trying 65.21.1.13... * Connection refused * Failed connect to 65.21.1.13:3000; Connection refused * Closing connection 1 Commented Jan 28, 2023 at 20:39
  • "When I open it in browser ... the service is working" - work out what is different between your browser request and your PHP request (and/or the Java version, etc). Are you running that PHP on the same machine/network as your browser? Is that IP on the public internet, does the PHP host really have access to it? I guess it is not the problem now but generally when having trouble try to simplify everything - remove all those headers to verify there's not some problem with them. How about your web server and API logs, any clues there? Commented Jan 28, 2023 at 21:02
  • Please do not share IPs, tokens, codes, passwords or anything similar. Commented Jan 29, 2023 at 3:16
  • Whats your actual error response? Commented Jan 29, 2023 at 3:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.