0

This is my url: http://xxx:5001/?messageId=2&baseId=1

If I open it in browser, work fine.

But if I open it with curl, I get error:

php curl Failed to connect to xxx port 5001: Connection refused

My php code:

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://xxx:5001/?messageId=2&baseId=1');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$res = curl_exec($ch);
echo curl_error($ch);;
print_r($res);
curl_close($ch);

Port 5001 is opened with firewall and IP not block by server

No NAME
  • 159
  • 1
  • 10
  • Does this answer your question? [Curl : connection refused](https://stackoverflow.com/questions/41027340/curl-connection-refused) – Angel Deykov Sep 18 '20 at 08:40
  • @AngelDeykov actually it does not. Resolving this issue for a localhost post is not the same quest as resolving this issue for a server sitting somewhere in internet lalaland. – YvesLeBorg Sep 18 '20 at 10:23

1 Answers1

0

I ran the code on my local machine and it works. Try the following:

  1. run the script on the command line >PHP script.php and check the errors
  2. if you have access to the server check the log #tail -f /var/log/error_log
  3. check for domain resolution. can the serve resolve the same name as your desktop/dev box?
  4. repeat step 1 from the server.

you will find the answer in one of those 4 steps.

Sergio Rodriguez
  • 8,258
  • 3
  • 18
  • 25
  • 1
    3.1 check that the provider of this API has it set for the port you are using; 3.2) validate that you are using the right http method (GET vs POST) ; 3.3 check with the API provider that `http` is allowed vis `https` – YvesLeBorg Sep 18 '20 at 10:28