简体   繁体   English

PHP Curl 未连接到具有 IP 地址和端口的 url

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

相关问题 Twilio Flask 应用程序视频通话未通过公共 IP 地址连接 - Twilio Flask app video call is not connecting over a public IP address 如何在 AWS EC2 实例中的公共而非私有 IP 地址的端口 3000 上运行应用程序(以便可以在 inte.net 上访问) - How to run application on port 3000 on Public and Not Private IP Address in AWS EC2 Instance (so it can be accessed on the internet) 在 bash 脚本中触发 aws php sdk 浏览器 URL 和 CURL 请求 - Trigger aws php sdk browser URL with CURL request in bash script Go:地址中缺少端口 - Go: Missing port in address 为反向代理后面的应用程序指定 URL 而不是 IP:port in.network 端点 - Specify URL instead of IP:port in network endpoints for applications behind reverse proxy Terraform 在 su.net 上查找 IP 地址 - Terraform Finding IP address available across subnets AWS - Fargate 任务的私有地址 static IP - AWS - Private static IP address for Fargate task 找不到使用公共 IP 地址在 Fargate 中运行的任务 - Task running in Fargate is not found with public IP address 谷歌索引 AWS 网络接口 IP 地址 - Google Indexing AWS Network Interface IP Address Curl URL 带双引号 - Curl URL with double quote
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM