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

試著忘記壹切 提交于 2019-12-11 01:25:52

问题


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 on hostgator.com.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6586981/curl-call-with-a-port-in-the-url-location-not-working-couldnt-connect-to-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!