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

仅限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条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名