在 nusoap 中传递 xml

发布于 2024-09-10 21:13:40 字数 1265 浏览 4 评论 0原文

美好的一天,

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

没有你我更好 2024-09-17 21:13:40

升级 libxml2 并重建 PHP。

Upgrade you libxml2 and rebuild PHP.

忆沫 2024-09-17 21:13:40

我根本不知道 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()

心的憧憬 2024-09-17 21:13:40

不确定您使用的 nusoap 版本是否与我不同,但我一直在使用代理,它似乎有效。我还使用soapclient而不是nusoap_client实例化客户端(以前没有见过):

 $client = new soapclient('http://localhost/nusoap/ws.php?wsdl', true);
 $proxy = $client->getProxy();
 $response = $proxy->call("myfunction", array('test' => 123));

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):

 $client = new soapclient('http://localhost/nusoap/ws.php?wsdl', true);
 $proxy = $client->getProxy();
 $response = $proxy->call("myfunction", array('test' => 123));
和影子一齐双人舞 2024-09-17 21:13:40

是的,答案就在 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.

暗恋未遂 2024-09-17 21:13:40

如果您想在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文