php - php中的curl超时与curl soap xml调用
问题描述
好吧,我在这个上扯掉我的头发。我根本没有使用过 PHP WDSL SOAP CURL XML 调用(它们都是单独的,但不是一起的!)并且努力获得响应或有意义的错误。
为了突出它,我有一个演示 WDSL 端点 ( http://office.keystonesupport.net:8084/DemoSoap/KSDSoap/KhaosKSD.exe/wsdl/IKosWeb?wsdl ),如果你坚持使用浏览器,它将以XML 详细说明一切。
然后我尝试编写 PHP 来访问一个不带输入参数的特定操作“GetVersion”
使用 Wizdler ( https://chrome.google.com/webstore/detail/wizdler/oebpmncolmhiapingjaagmapififiakb ) 发布,它显示了请求标头
SOAPAction: "urn:IKosWebIntf-IKosWeb#GetVersion"
Content-Type: text/xml; charset="utf-8"
和身体
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetVersion xmlns="http://tempuri.org/"/>
</Body>
</Envelope>
我得到回应
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:IKosWebIntf-IKosWeb">
<NS1:GetVersionResponse>
<return xsi:type="xsd:string">8.149.29</return>
</NS1:GetVersionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
所以我把它放到我的脚本中,如下。但它只是给出了 curl 超时错误?
$xml='<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetVersion xmlns="http://tempuri.org/"/>
</Body>
</Envelope>';
$url='http://office.keystonesupport.net:8084/DemoSoap/KSDSoap/KhaosKSD.exe/wsdl/IKosWeb?wsdl';
$ch = curl_init();
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"SOAPAction: \"urn:IKosWebIntf-IKosWeb#GetVersion"",
);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
print_r ($headers);
echo '<br>';
echo htmlentities($xml);
echo '<br>';
$response = curl_exec($ch);
if($response === false) {
$err = 'Curl error: ' . curl_error($ch);
curl_close($ch);
print $err;
}else{
curl_close($ch);
var_dump($response);
}
解决方案
似乎在线上有语法错误
"SOAPAction: \"urn:IKosWebIntf-IKosWeb#GetVersion"",
它应该是
"SOAPAction: \"urn:IKosWebIntf-IKosWeb#GetVersion\"",
修复此问题后,代码对我有用。
LE:最终发现问题在于端口 8084 被 ISP 过滤/阻止。所以,“连接超时”就是因为这个。
推荐阅读
- c++ - 检查 char 数组中的前导字符的最快方法是什么?
- python - Django rest框架自定义权限不起作用
- c++ - gcovr 总是显示 100% 的线路覆盖率
- python-3.x - 一个函数中的用户定义输入在另一个函数Python中不返回值
- mysql - 如何仅使用最后一个事务来计算 timediff mysql 5.7
- python - 如何在 Python 中使用零偏度对数变换
- python - 将 Tensorflow1.12 模型转换为 Tensorflow Lite (TFLite)
- c - 为什么使用 libc 会阻止货物正确链接我的程序?
- spring - 通过 CompletableFuture 工作的 Spring-boot 异步控制器同步
- html - 用 html5 SVG 设计日食圆