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

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况