douchendan0040
2017-05-24 09:51
浏览 121
已采纳

仅限http服务器上的CURL错误“无法连接到主机”

i call a CURL code for calling a URL (the URL sends an email). When i call the URL from the browser, it works, but when i execute it from the curl php code, it doesn't work.

also, the exact same curl code works on my https SSL production server, but not on my http development server.

The error i get on my development http server is "couldn't connect to host".

This is the code:

$ch = curl_init();

$requestedUrl = http://XXX.XXX.XX.XX/myproject/index.php?entryPoint=viewReport&record=.....etc..

curl_setopt($ch, CURLOPT_URL, $requestedUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);
if ($data === FALSE) {
    $GLOBALS['log']->fatal("error = " . print_r(curL_error($ch),true));
}

curl_close($ch);

i read every post there is on this issue. i don't know if i'm behind proxy or not and i dont know how to get the ip of the proxy if i'm behind one.

i have tried adding curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

tried adding :

curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, "http://XXX.XXX.XX.XX"); //your proxy url
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number

tried opeining port 1080 in the firewall (which is open for any http address).

i'm out of ideas, so please help me :)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongruidian3064 2017-06-04 08:35
    已采纳

    i just changed the IP of the url to "localhost" and it worked :) $requestedUrl = http://localhost/myproject/index.php?entryPoint=viewReport&record=.....etc..

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题