CURL:无法连接到exampleurl.com端口443:连接被拒绝

时间:2018-03-01 10:16:15

标签: php web-services curl

每当我尝试通过CURL(PHP)连接API时,我在邮递员成功响应时遇到“无法连接到exampleurl.com端口443:连接被拒绝”错误。代码在开发服务器中运行。

这是我的卷曲代码

$ch       = curl_init();
$headers  = array(
  "Authorization: $this->header_token" // my token
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$res = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if(curl_error($ch))
{
    echo 'error:' . curl_error($ch); //giving error
}
 curl_close($ch);

if($http_status == 200){
  return json_decode($res,true);
}

有一件事,我最近得到了这个错误,以前它工作正常,没有任何问题。 任何建议或解决方案,请帮助。

1 个答案:

答案 0 :(得分:1)

添加此选项我面临同样的问题然后解决了

curl_setopt( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
相关问题