【发布时间】:2016-05-08 07:48:47
【问题描述】:
我正在使用 curl 调用 Web 服务,它在 localhost 中运行良好,但是当我在我的实时网站上使用相同的脚本调用它时会输出错误:
无法连接到主机
$soap_request = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<InsertData xmlns="http://exampleServiceSite:6265">
<remarks>No Remarks</remarks>
<insuranceValue>0</insuranceValue>
</InsertData>
</soap:Body>
</soap:Envelope>';
$header = array(
"POST /Service1.asmx HTTP/1.1",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"http://exampleServiceSite:6265/InsertData\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://exampleServiceSite:6265/" );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($soap_do);
var_dump($result);
【问题讨论】:
-
需要设置代理吗? 6265端口是否开放?
-
@David 我希望使用的网络服务来自第 3 方,所以我无法检查该第三方网络服务的端口,还是您的意思是我需要检查我的实时网络服务器上的 6265 端口?
-
端口 6265 需要两边都打开。如果将 url 更改为 google.com 会怎样?您仍然无法连接到主机吗?如果是,请尝试设置 curl 代理。
-
@David 与 google.com 一起工作正常,即加载 google.com 页面不会出现任何错误
-
抱歉,我帮不了你。变化是只允许传统端口。请咨询服务器的支持团队
标签: php web-services curl localhost