我可以使用 PHP 的 SoapClient 来解析 SOAP 响应,而不发出 HTTP 请求吗?
我目前正在处理一个过时的支付处理器,它使得连接到他们的服务变得尽可能困难(包括自定义客户端 SSL 证书,带有密码,再加上基本的 HTTP 身份验证)。长话短说,我无法使用 SoapClient 发出请求,但我可以使用 cURL 来做到这一点。
我现在有字符串形式的响应,我可以使用 SoapClient
来解析它吗?我不想将其作为常规 XML 手动解析,因为我必须重复很多功能,例如在查找
时抛出合理的异常,例如例子。
I'm currently dealing with an archaic payment processor that makes connecting to their service as hard as possible (including a custom client SSL cert, with a password, plus basic HTTP Auth after that). Long story short, I can't use SoapClient to make the request, but I have been able to do it with cURL.
I now have the response in a string, can I use SoapClient
to parse it? I'd rather not have to parse it manually as a regular XML, since I'd have to duplicate a lot of functionality, like throwing a sensible exception when finding a <SOAP:Fault>
, for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,你不能。
(只是为了后代回答这个问题。由于缺乏相反的证据,您显然不能使用 SoapClient 来解析您已有的 SOAP 响应)
No, you can't.
(just answering this for posterity. Based on the lack of evidence to the contrary, you apparently can't use SoapClient to parse a SOAP response you already have)
您可以使用
SoapClient 的
告诉 SoapClient 使用 SSL 证书等。可以使用context
选项定义上下文stream_context_create
与很多选项You can define context using
context
option ofSoapClient
to tell SoapClient to use SSL certificates etc. Context may be created usingstream_context_create
with lots of options让我们再想象一下您调用了 SoapClient::__doRequest() 并且它将您的 XML SOAP 响应返回到一个名为 $response 的变量中。
这只是一些示例/伪代码(未经测试并且无法按原样工作)。我的观点是,您手动获取了 SOAP 响应,因此现在您所要做的就是解析它。 SimpleXML 是您可以使用的一个解决方案这样做。
Let's for a second imagine you had called SoapClient::__doRequest() and it returned your XML SOAP response into a variable called $response.
That is just some example/pseudo code (not tested and won't work as-is). My point is that you manually acquired the SOAP response so now all you have to do is parse it. SimpleXML is one solution you could use to do that.