使用 PHP 进行 HTTP 请求努肥皂
我正在尝试创建对我们的 Web 服务的 http 请求,当直接输入到 Web 服务测试输入字段并单击“调用”时,我的测试 XML 可以正常工作,但是当尝试通过 PHP + NuSoap 使用相同的数据时,我得到了我无法解决的特殊错误,我尝试用谷歌搜索它,但没有显示与此案例相关的内容。
这是请求:
POST /iInterface_pc2/service.asmx HTTP/1.0
Host: 10.10.86.55
User-Agent: NuSOAP/0.9.6dev (1.137)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.xxxx.com.cn/TransferMaterialInfo"
Content-Length: 722
<?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>
<TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
<Materiallist>
<Materialinfo>
<id>123456</id>
<title>Hello word</title>
<datetime>2011-04-23 12:12:12</datetime>
<contributor>Some One</contributor>
<materialurl>www.website.com/path/audio1.mp3</materialurl>
<duration>10000</duration>
<status>0</status>
<remark></remark>
</Materialinfo>
</Materiallist>
</TransferMaterialInfo>
</soap:Body>
</soap:Envelope>
和响应:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 28 Apr 2011 11:04:11 GMT
Connection: close
Content-Length: 428
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> Value cannot be null.
Parameter name: s</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
最后是我用来生成请求的 PHP
<?php
// include soap file
require_once('lib/nusoap.php');
// set end point
$endpoint = "http://10.10.86.55/iInterface_pc2/service.asmx";
// create client
$client = new nusoap_client($endpoint);
if ( $client->getError() ) {
print "Soap Constructor Error: ";
print_r($client->getError());
}
// Human readable
$request = <<<HEREDOC
<TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
<Materiallist>
<Materialinfo>
<id>123456</id>
<title>Hello word</title>
<datetime>2011-04-23 12:12:12</datetime>
<contributor>Some One</contributor>
<materialurl>www.website.com/path/audio1.mp3</materialurl>
<duration>10000</duration>
<status>0</status>
<remark></remark>
</Materialinfo>
</Materiallist>
</TransferMaterialInfo>
HEREDOC;
$action = "http://www.xxxx.com.cn/TransferMaterialInfo";
$msg = $client->serializeEnvelope($request, '', array(), 'document', 'encoded', '');
$result = $client->send($msg, $action);
if ( $client->fault ) { //soap_fault
print "Soap Fault :";
print_r($client->fault->faultcode);
print_r($client->fault->faultstring);
}
elseif ( $client->getError() ) {
print "Soap Error :";
print_r($client->getError());
}
else {
print "Result: ";
print_r($result);
}
..print stuff
?>
任何见解和猜测都非常感谢。我已经用头撞砖墙已经有一段时间了。 :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信服务器正在看到 <和>字符并将其解码为 >
您可能需要在发送之前对数据进行 urlencode
I believe the server is seeing the < and > characters and decoding it to >
You may need to urlencode the data before sending
我不确定这是否对您有帮助,但请以任何方式检查
http://mohammed-magdy.blogspot.com/2011/04/creating-web-services-using-php.html
i am not sure , if that will help you or not , but check it any way
http://mohammed-magdy.blogspot.com/2011/04/creating-web-services-using-php.html
该问题已解决,实际上是由错误的 ASP 代码导致的,该代码期望仅对空格进行 html 编码,从而导致错误的响应。
The problem has been solved and was actually caused by faulty ASP code expecting only whitespaces to be html-encoded, resulting in faulty response.