如何减少 SOAP 响应中的字节数?
有没有办法减少从 SOAP 响应发送到网络的字节数?我在 PHP 中使用 nuSoap 并希望避免每个节点中的 xsi:type="xsd:string", xsi:type="xsd:int" 。 有办法做到吗?
提前致谢 c.
is there a way to reduce the number of bytes sent to the network from a SOAP response? I use nuSoap in PHP and would like to avoid xsi:type="xsd:string", xsi:type="xsd:int" in every node.
Is there a way to do it?
Thanks in advance
c.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您严格限制将有效的 SOAP 响应发送回 Flash 客户端,并且使用有效架构不是一个选项(这将简化输出标记),那么不,您对此无能为力 ...
但是,如果您不依赖于发送有效的 SOAP 响应,并且您的开发人员确实坚持获得非详细标记,那么您就可以选择自己滚动。如果是这种情况,请继续阅读。
您可以通过 PEAR 或 一些其他来源。如果你想走 Trully-Roll-Your-Own 路线,有 PHP 类帮助您直接创建有效的 XML 。
不要重复其他地方所说的内容,这里是有关如何使用 PEAR XML_Serializer 序列化某些数据的深入示例。
另一个非常简单的示例,这次它是基于 SimpleXML 的,您可以根据需要添加子元素和属性以满足所需的输出。
上面的代码会产生类似以下内容:
我希望它有帮助。
If you are strictly tied to sending valid SOAP response back to Flash client, and if using valid schema is not an option (which would simplify output markup), then no, you can't do anything about it...
However, if you're NOT tied to sending valid SOAP response, and your developer really insists on getting non-verbose markup, then you are left with an alternative of rolling your own. If this is the case, read on.
You can use some of existing XML Serializer classes available via PEAR, or some other source. If you wanted to go down the Trully-Roll-Your-Own route, there are PHP classes to aid you in creating valid XML directly.
Not to repeat what's being said elsewhere, here's in-depth example about how to serialize some data using PEAR XML_Serializer.
Another really simple example, this time it's SimpleXML-based, where you add child elements and attributes as needed to meet desired output.
Code above would produce something like:
I hope it helps.
通常的方法是在 HTTP 层启用压缩。如果您想确保始终压缩数据,您甚至可以拒绝未压缩的 SOAP 请求。 (流行的软件问答网站就是这样做的。)
The usual way to do this is to enable compression in the HTTP layer. If you want to make sure that you're always compressing data, you could even reject SOAP requests that are not compressed. (A popular software Q&A site does this.)
在传输过程中删除空格并对内容进行 gzip 压缩。
Remove whitespaces and gzip the contents during transport.