[英]PHP Curl Not connecting to a url with IP Address and PORT
Have made and deployed an app on an AWS EC2 instance, and accessing the app via ip_address:port, where ip_address is the elastic ip associated with the instance.在 AWS EC2 实例上制作并部署了一个应用程序,并通过 ip_address:port 访问该应用程序,其中 ip_address 是与实例关联的弹性 ip。
I am able to make API calls to this app using postman, and via cmd.我可以使用 postman 和通过 cmd 对该应用程序进行 API 次调用。
However, when I try to make POST request using PHP Curl on Wordpress (hosted on Bluehost), I keep getting the但是,当我尝试在 Wordpress(托管在 Bluehost)上使用 PHP Curl 发出 POST 请求时,我不断收到
Failed to connect to ip_address port XXXX after 0 ms: Connection refused. 0 毫秒后无法连接到 ip_address 端口 XXXX:连接被拒绝。
Any ideas of what I might be missing?关于我可能遗漏的任何想法?
'''php '''php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http:ip_address:8000/payments/accounts/v1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_TIMEOUT => 1000,
CURLOPT_CONNECTTIMEOUT => 1000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_CUSTOMREQUEST => 'POST',));
print_r(curl_error($curl));
curl_exec($curl);
curl_close($curl);
'''
Getting this response得到这个回应
'''code Failed to connect to id_address port 8000 after 0 ms: Connection refused ''' '''代码在 0 毫秒后无法连接到 id_address 端口 8000:连接被拒绝'''
Using the redacted ip and a slightly modified version of your code as follows:使用经过编辑的 ip 和代码的稍微修改版本如下:
$url='http://X.XXX.XX.XX:8000/payments/accounts/v1';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_CONNECTTIMEOUT => 1000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST=>true
)
);
$res=curl_exec( $curl );
curl_close( $curl );
printf('<pre>%s</pre>',print_r( $res, true ));
Yields:产量:
{"detail":"Authentication credentials were not provided."}
Perhaps if you were to actually include and submit some post data in the CURLOPT_POSTFIELDS
option you might find a different response.或许如果您实际在
CURLOPT_POSTFIELDS
选项中包含并提交一些发布数据,您可能会发现不同的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.