0

I can access my test Node site (http://18.220.168.1:8888) from a browser just fine. However, when I attempt to cURL using PHP's cURL, I get:

Array
(
    [curl_error] => Failed to connect to 18.220.168.1 port 8888: Connection refused
    [error_number] => 7
)

My cURL setup is:

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// Temporary for testing self-signed sites
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: '.$data_type,                                                                                
    'Content-Length: ' . strlen($data),
    'Public-Key: ' . $pub_key,
    'Private-Key: ' . $priv_key,
    'Authorization: Bearer ' . $pub_key,)                                                                       
);

$result = curl_exec($ch);

I am hosting on Amazon's EC2, and the ports are open (obviously since I can access it via my browser). Any idea what I'm doing wrong here by chance?

Thanks

EDIT

I just tested with resteasy's tester, and it connected just fine. So it has to be something either in the cURL request, or between the browsers.

6
  • what is $url set to?
    – Mike
    Nov 15, 2017 at 13:35
  • The URL above for the node server: http://18.220.168.1:8888. I've tried with and without the http://.
    – James
    Nov 15, 2017 at 13:40
  • Looks like a firewall issue. On what machine are you running this code? Nov 15, 2017 at 17:45
  • @MichaelHampton I'm running it from a test script on another AWS ec2 instance that I built to test API calls. They both use the same security group, so both have port 8888 open. However, I literally just tested with resteasy's tester, and it connected just fine. So it has to be something either in the cURL request, or between the browsers.
    – James
    Nov 15, 2017 at 18:03
  • With the error of "connection refused", I would agree with a firewall issue. Try using tcping or tcptraceroute to port 8888 and verify it can really connect.
    – Ken S.
    Nov 15, 2017 at 19:29

1 Answer 1

0

I feel so stupid. I just realized I was doing this from a cPanel server that had CSF installed. After adding this port to CSF, it worked. I'll leave this up in case it helps anyone else who is having a brain fart.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .