使用curl报couldn't connect to host异常

WBOY
Release: 2016-06-13 13:23:55
Original
1631 people have browsed it

使用curl报couldn't connect to host错误

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->//发送post请求
function _xpost($url,$p)
{
    $f='';
    $data='';
    foreach($p as $k=>$v)
    {
        $data.=$f.$k.'='.urlencode($v);
        //$data.=$f.$k.'='.$v;
        $f='&';
    }
    //echo $data.'';

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);  
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $res = curl_exec($curl);

    if(curl_errno($curl))
    {
        echo 'Curl error: ' . curl_error($curl);
    }
    curl_close($curl);
    return $res;
}
Copy after login

我调用这个函数发一条短信,在本地服务器执行的时候能正常运行,可是部署到网络服务器上去就报了Curl error:couldn't connect to host错误,请问怎么回事啊?怎么解决

------解决方案--------------------
你在服务器上ping一下那个主机网址看看是不是通的?

有可能是服务器的DNS服务器设置问题,导致找不到这台主机,还有就是你的服务器ip被对方屏蔽了也会出现这样的提示
------解决方案--------------------
同意楼上
------解决方案--------------------
你用 foskopen能不能连接
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template