开发者

cURL call with a port in the url/location not working - couldn't connect to host

开发者 https://www.devze.com 2023-03-17 05:58 出处:网络
I am trying to make a cURL call to a url that looks like this: https://example.com:9000/test When I execute the following code, I get curl error 7 couldn\'t connect to host.

I am trying to make a cURL call to a url that looks like this:

https://example.com:9000/test

When I execute the following code, I get curl error 7 couldn't connect to host.

$headers = array(
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_CONNECTTIMEOUT => 5,
  CURLOPT_TIMEOUT => 10,
  CURLOPT_URL => 'https://example.com:9000/test',
);
$headers[CURLOPT_SSL_VERIFYPEER] = FALSE;
$headers[CURLOPT_SSL_VERIFYHOST] = 2;
$ch = curl_init(); 
curl_setopt_array($ch, $headers);
$response = curl_exec($ch);

If I set the url to https://example.com/test, I am able to connect to the host, just not to what I need to get.

I have also tried setting <code>CURLOPT_PORT => 9000</code> with the same result (error 7).

One other note, I am able to use cURL with the url on some machines but not others. My Windows machine works fine, but the linux server I'm on is the one having issues. Another linux server seems to work fine as well.

EDIT: Server is shared hosting开发者_JAVA技巧 on hostgator.com.


If anyone else has this problem, contact your server host. I contacted hostgator.com and they responded with the following:

I have opened the outbound port 9000 for you.

Everything works now.


check the url in IE browser. if it works fine then remove the timeout params and try.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号