简体   繁体   English

无法连接到:连接被拒绝 - cURL PHP

[英]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 refusedCURLINFO_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.

相关问题 curl无法连接拒绝连接 - curl Failed to connect Connection refused php curl 无法连接到 xxx 端口 5001:连接被拒绝 - php curl Failed to connect to xxx port 5001: Connection refused Cloudinary的PHP Upload API中的cURL错误-“无法连接到端口443:连接被拒绝” - cURL Error in Cloudinary's PHP Upload API - “failed to connect to port 443: connection refused” 无法连接到端口 8080:连接被拒绝错误号:7 (cURL) - Failed to connect to port 8080: Connection refused Error number: 7 (cURL) curl: (7) 无法连接到本地主机端口 3000:连接被拒绝 - curl: (7) Failed to connect to localhost port 3000: Connection refused cURL错误7:无法连接到本地主机端口4444:连接被拒绝 - cURL error 7: Failed to connect to localhost port 4444: Connection refused curl(7):无法连接到本地主机端口8000:连接被拒绝 - curl (7): Failed to connect to localhost port 8000: Connection refused cURL 错误 [0]:无法连接到 127.0.0.1 端口 8545:连接被拒绝 - cURL error [0]: Failed to connect to 127.0.0.1 port 8545: Connection refused CURL:无法连接到exampleurl.com端口443:连接被拒绝 - CURL: Failed to connect to exampleurl.com port 443: Connection refused PHP curl 尝试通过代理连接时连接被拒绝 - PHP curl Connection refused when trying to connect through a proxy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM