在 nusoap 中传递 xml
美好的一天,
我在 nusoap 中传递 xml 时遇到问题。
样本: 我通过这个 xml
<test>123</test>
nusoap 响应是
test123/test
大于和小于符号被删除。
这是我的服务器代码:
require_once('nusoap/nusoap.php');
$server = new nusoap_server; // Create server instance
$server->configureWSDL('demows','http://example.org/demo');
$server->register('myFunction',
array("param"=>"xsd:string"), // input
array("result"=>"xsd:string"), // output
'http://example.org/demo'
);
function myFunction($parameters) {
return $parameters;
}
// Use the request to try to invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';
$server->service($HTTP_RAW_POST_DATA);
这是我的客户端代码:
require_once('nusoap/nusoap.php');
$client = new nusoap_client('http://localhost/nusoap/ws.php?wsdl', true);
$clientparam = '<test>123</test>';
$result = $client->call('myFunction',
array('param'=>$clientparam)
);
print_r($result);
*请注意,上述代码适用于 PHP 版本 5.3.0,但不适用于 PHP 版本 5.2 .0-8+etch13,这是我们生产中使用的。
我在网上搜索了 2 版本的任何问题,但没有发现。 非常感谢任何帮助。 TIA
Good day,
I am having trouble passing an xml in nusoap.
sample:
I pass this xml
<test>123</test>
The nusoap response is
test123/test
The greater than and less than sign is removed.
This is my code for the server:
require_once('nusoap/nusoap.php');
$server = new nusoap_server; // Create server instance
$server->configureWSDL('demows','http://example.org/demo');
$server->register('myFunction',
array("param"=>"xsd:string"), // input
array("result"=>"xsd:string"), // output
'http://example.org/demo'
);
function myFunction($parameters) {
return $parameters;
}
// Use the request to try to invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';
$server->service($HTTP_RAW_POST_DATA);
This is my code for the client:
require_once('nusoap/nusoap.php');
$client = new nusoap_client('http://localhost/nusoap/ws.php?wsdl', true);
$clientparam = '<test>123</test>';
$result = $client->call('myFunction',
array('param'=>$clientparam)
);
print_r($result);
*Note that the above code is working on PHP Version 5.3.0 but NOT on PHP Version 5.2.0-8+etch13 which is the one on our production is using.
I've searched the net for any issues on the 2 version but none found.
Any help is highly appreciated. TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
升级 libxml2 并重建 PHP。
Upgrade you libxml2 and rebuild PHP.
我根本不知道 nusoap,但听起来你的实体正在被丢弃。
可能值得控制两端的实体,例如通过更改“>”对于 >、'<'对于<手动或使用 htmlentities() 等函数
I don't know nusoap at all, but it sounds like your entities are being discarded.
It might be worth controlling the entities at either end, for instance by changing '>' for >, '<' for < either manually or using a function such as htmlentities()
不确定您使用的 nusoap 版本是否与我不同,但我一直在使用代理,它似乎有效。我还使用soapclient而不是nusoap_client实例化客户端(以前没有见过):
Not sure if you're using a different version of nusoap than me, but I've been using the proxy, which seems to be working. I also instantiate the client with soapclient rather than nusoap_client (hadn't seen that before):
是的,答案就在 soapval 类中。
这里是一个有点混乱但简单的例子。
快速 - 你必须用这个类包装任何非通用类型,这意味着 php 数组。这种包裹的嵌套当然可能发生,但这并不违反设计。
Yes and the answer is in soapval class.
Little messy but simple example is here.
In quick - you have to wrap with this class any non-generic type, that means i.e. php array. Nesting of this wraps could of course happen but it's not against design.
如果您想在soap消息中传递xml值并且您控制服务器和客户端(或者至少您可以指示客户端),为什么不对您的xml进行base64编码。然后解析器只会将其视为普通字符串,而不会感到困惑。
If you want to pass xml value within a soap message and you control both the server and the client (or at least you can instruct the client), why not base64 encode your xml. Then the parser will just see it as a normal string and not get confused.