1

I am connecting to a 3rd party API with php curl, on localhost it's working fine and is successfully connected. but with same code it returns failed: connection refused on live server.

$url = "http://suitefleetdms.com:8246/api/authenticateweb";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$verbose = fopen('php://temp', 'w+');
curl_setopt($curl, CURLOPT_STDERR, $verbose);

$headers = array(
 "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = '{"username":"cbs.dev@transcorp-intl.com","password":"MY_REAL_PASSWORD"}';

curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);

echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";

I tried connecting this domain:port from

  • terminal with command curl -v https://suitefleetdms.com:8246/api/authenticateweb {expected response code 404 because missing body but concern here is establish connection}
  • postman (web based and app on MacOS), it connects successfully.
  • MacOS Terminal , it connects successfully
  • PHP cURL on localhost (xampp on macOS BigSur 11.1 PHP Version 7.4.1 ), it connects successfully

BUT whenever i run same PHP cURL code on live server it returns connection refused. PHP Version 7.4.21

attaching all screenshots

postman application postman web php curl on localhost terminal macOS

live server (not working)

Their API Documentation is here

SAFDAR IQBAL
  • 11
  • 1
  • 5
  • 1
    Most probably your live server is banned from the host of the webservice you're calling or you have networks issues. This is not coding related, your code just works fine. – Andrea Olivato Jul 25 '21 at 08:45
  • thanks for your reply @Andrea. I have tried multiple live servers for this but issue still persists. Also those servers never came in contact with this service before. I am curious if postman web is working then my servers should also work. As a developer I would love to learn the reason, for now I have tried everything to print more and more info but I cant get the reason. – SAFDAR IQBAL Jul 25 '21 at 11:30

0 Answers0