[英]Failed to connect to : Connection refused - cURL PHP
So here's the scenario.所以这是场景。
1) On my local machine that is running MAMP, I'm not facing any issue and I'm able to successfully get the response along with CURLINFO_HTTP_CODE=200
1) 在我运行 MAMP 的本地机器上,我没有遇到任何问题,我能够成功获得响应以及CURLINFO_HTTP_CODE=200
2) However, there is a remote server on which my PHP code is deployed. 2) 但是,我的 PHP 代码部署在远程服务器上。 If I try to run the same thing (as I've mentioned in #1) I get an error that says如果我尝试运行相同的东西(正如我在 #1 中提到的),我会收到一个错误消息
curl_error = Failed to connect to my_ip port my_port: Connection refused
with CURLINFO_HTTP_CODE = 7
curl_error = Failed to connect to my_ip port my_port: Connection refused
, CURLINFO_HTTP_CODE = 7
$url = 'myURL';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,30); //timeout in seconds
curl_setopt($ch,CURLOPT_TIMEOUT, 20); // same for here. Timeout in seconds.
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$data_string = {"name":"mark"} ` $data_string = {"name":"mark"} `
In my case, call API from localhost was successful, but when i call API from online website i get error(connection refused).就我而言,从本地主机调用 API 是成功的,但是当我从在线网站调用 API 时,出现错误(连接被拒绝)。 that's because the IP of API was available on our internal network(company network), not on the internet.那是因为 API 的 IP 在我们的内部网络(公司网络)上可用,而不是在 Internet 上。 i know it's silly mistake.我知道这是一个愚蠢的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.