【发布时间】: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