【发布时间】:2019-06-18 17:32:56
【问题描述】:
我正在尝试使用 PHP 的 cUrl 和 file_get_content() 从以下 URL 获取响应-
https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg?user=<USERNAME>&pass=<PASSWORD>&msisdn=<MSISDN>&trxid=<TRANSACTION_ID>
为简单起见-
https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg
对于有效请求,它会以交易的详细信息响应 XML,但对于第二个 url 或任何参数不正确的请求,它会从浏览器或邮递员响应如下内容-
<transactions>
<transaction>
<trxStatus>1002</trxStatus>
<trxId>6E72D8VS02</trxId>
<reference/>
</transaction>
</transactions>
我已经编写了一个 php 代码来获得这样的响应-
$endPoint = "https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg?user=xxxx&pass=xxxx&msisdn=xxxx&trxid=xxxx";
$xmlString = file_get_contents($endPoint, FILE_TEXT);
也尝试使用 cURL as-
$curl = curl_init($endPoint);
curl_setopt($curl, CURLOPT_PORT, 9081); // Tried with or without
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$xml_string = curl_exec($curl);
问题:在这两种情况下,我都能从 localhost 得到完美的响应,但是当我从 Web 服务器执行它时,连接被拒绝。
错误显示类似这样的内容-
file_get_contents()
无法打开流:连接被拒绝
curl_error()
无法连接到主机
值得一提的是,这两个函数都可以在服务器中用于任何其他 URL,例如 https://google.com
我找到了this almost similar question in stackoverflow,但不幸的是它没有任何答案。
主机站点有任何限制吗?或者我错过了什么或需要做任何额外的事情?或者它不适用于不同的端口而不是 80?
【问题讨论】:
-
您必须尝试此问题中列出的所有解决方案。我相信其中一个肯定会起作用:- How to resolve cURL Error (7): couldn't connect to host?
-
主机IP可能被屏蔽
-
实际上根本无法从家庭或工作服务器连接到该 URL
-
@AlivetoDie 我已经测试了所有可能的解决方案,但不幸的是没有奏效,
-
@tim 我已经在两个不同的服务器上进行了测试,并且 URL 也适用于 google 见解,请访问-developers.google.com/speed/pagespeed/insights/…