【问题标题】:CURL: Failed to connect to exampleurl.com port 443: Connection refusedCURL:无法连接到 exampleurl.com 端口 443:连接被拒绝
【发布时间】:2018-08-09 09:14:52
【问题描述】:

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

这是我的 curl 代码

$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);
}

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

【问题讨论】:

  • 如果它在此之前有效,那么其他东西可能已经改变了。你能通过 cli ping 那个 url 吗?可能是防火墙问题。

标签: php web-services curl


【解决方案1】:

添加这个选项我遇到了同样的问题然后它解决了

curl_setopt( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

【讨论】:

  • 感谢您的回答,实际上存在一些服务器问题,他们已解决并且可以正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多