简体   繁体   English

PHP使SOAP客户端请求返回500内部服务器错误

[英]PHP Make SOAP Client Request Returns 500 Internal Server Error

I'm using PHP to make SOAP request. 我正在使用PHP发出SOAP请求。 I do have information of the web service from the third party. 我确实有来自第三方的Web服务信息。 Basically what they have give me: 基本上他们给我的是:

  1. The full URI request ( http://xx.xx.xx.xx:xxxxxx/some/services/BasicDo ) 完整的URI请求( http://xx.xx.xx.xx:xxxxxx / some / services / BasicDo
  2. Username & Password 用户名密码

I am pretty new however I could understand a bit how PHP SOAP things work. 我很新,但是我可以了解一点PHP SOAP的工作原理。 However in the example I found the URL called is something like http://xx.xx.xx.xx/services/myservice?wsdl which is not really same with what I have with me. 但是,在示例中,我发现所调用的URL类似于http://xx.xx.xx.xx/services/myservice?wsdl ,与我所拥有的URL并不完全相同。 Additional question here is what should I ask them? 这里的另一个问题是我应该问他们什么? Perhaps what is the name of wsdl file? wsdl文件的名称是什么?

Also so far I have this code with me: 到目前为止,我还拥有以下代码:

try{
    $client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));
}
catch(SoapFault $fault) {
    trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}

But from the console, I received status 500 Internal Server Error. 但是从控制台,我收到状态500内部服务器错误。 I don't know how this can be, I am expecting something from the catch block. 我不知道这是怎么回事,我希望从catch块中得到一些帮助。 Somebody please clarify me this. 有人请给我澄清一下。 Thank you in advance. 先感谢您。

Unfortunately, it seems like no matter what you try (eg passing array('exceptions' => 0) , SoapClient() will throw an uncatchable E_ERROR on network connection issues. This bug is still present as high up as PHP 5.5.4 ( REF ). 不幸的是, 无论您如何尝试 (例如,传递array('exceptions' => 0)SoapClient()都会在网络连接问题上抛出不可捕获的E_ERROR。此错误仍然存​​在于PHP 5.5.4以上( REF )。

Summary: 摘要:

Test script: 测试脚本:

$client=@new SoapClient('garbage',array('exceptions'=>FALSE));
echo 'OK';

Expected result: We should see "OK", 预期结果:我们应该看到“确定”,

Actual result: 实际结果:

If we use register_shutdown_function to display the contents of error_get_last() , we get: 如果使用register_shutdown_function显示error_get_last()的内容, error_get_last()得到:

Array
(
    [type] => 1
    [message] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'garbage' : failed 
to load external entity "garbage"
)

To explain why you suddenly get this error without changing anything on your system, and to explain why SoapClient works on your local machine and not on your production system, it is most likely a firewall issue. 为了解释为什么突然不带任何错误而没有更改系统上的错误,并解释为什么SoapClient在本地计算机而不是生产系统上运行的原因,很可能是防火墙问题。

Here is what another person reported that solved his problem: 这是另一个报告解决了他的问题的内容:

I solved my problem. 我解决了我的问题。 It was actually an issue with my firewall. 这实际上是我的防火墙的问题。 The firewall was dropping packets sent via PHP, but via curl or wget were not being dropped. 防火墙正在丢弃通过PHP发送的数据包,但不会丢弃通过curl或wget发出的数据包。 I added a rule for all traffic from that server and increased the packet drop length and everything is working great now! 我为来自该服务器的所有流量添加了一条规则,并增加了数据包丢弃长度,并且现在一切正常!

Advice: 忠告:

My best advice at this time to write some code in the same PHP file that checks if the SOAP service url resolves and loads properly before calling the SoapClient. 目前,我的最佳建议是调用SoapClient 之前 ,在同一PHP文件中编写一些代码,以检查SOAP服务url是否正确解析和加载。

I am not sure what the issue may be but I did the following to debug this issue when I encountered it 我不确定问题可能是什么,但是遇到问题时我做了以下调试工作

$client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));

Things you can do: 您可以做的事情:

  1. Create a PHP file. 创建一个PHP文件。 Name it anything. 给它起任何名字。 Write the following code there: 在此处编写以下代码:

    ini_set('display_errors','On'); ini_set('display_errors','On');

    $client = new SoapClient(" http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl ", array('login'=>"myusername",'password'=> "mypwd")); $ client = new SoapClient(“ http://xx.xx.xx.xx:xxxxx / some / services / BasicDo?wsdl ”,array('login'=>“ myusername”,'password'=>“ mypwd”) ); var_dump($client); var_dump($ client); exit; 出口;

  2. Run the file. 运行文件。

  3. Chances are this will show you the required exception. 这很可能会向您显示所需的异常。

In my case, Our server used a proxy which I had not passed in the parameters due to which I was getting the issue. 就我而言,我们的服务器使用了一个代理,由于出现问题,我没有传递参数。 Let us know how it goes. 让我们知道怎么回事。

Thanks 谢谢

Add these codes at head of the file to see where the error happen 将这些代码添加到文件的开头,以查看错误发生的位置

ini_set('display_errors','1');
error_reporting(E_ALL);

First you need to make sure you have access to the SOAP server. 首先,您需要确保可以访问SOAP服务器。

From the machine that is running your php script try to access the wsdl file and check if it is valid. 从运行您的php脚本的计算机上,尝试访问wsdl文件并检查其是否有效。

you can for example use wget http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl then open the saved file and see what you are getting. 例如,您可以使用wget http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl然后打开保存的文件并查看得到的内容。 Is it a valid wsdl? 它是有效的wsdl吗?

Once you have sorted out our access, then you need to read the documentation here and here . 整理好我们的访问权限后,您需要在此处此处阅读文档。 You may need to authenticate differently or pass other options. 您可能需要进行其他身份验证或通过其他选项。

As for why the catch block is not picking up your exception, you are only catching SoapFault . 至于为什么catch块没有捕获您的异常,您只捕获了SoapFault The 500 internal server error can be caused by anything. 500内部服务器错误可能是由任何原因引起的。

I really appreciate all of the answers given. 我真的很感谢所有给出的答案。 I am actually working with another party which I don't have any access on the remote side. 我实际上正在与另一方进行合作,而该方在远程方没有任何访问权限。 My job is to make SOAP request to the server. 我的工作是向服务器发出SOAP请求。 However it turned out that there is NO web service available for me. 但是事实证明,没有适合我的Web服务。 So I ended up using cURL to send raw POST of SOAP request. 所以我最终使用cURL发送SOAP请求的原始POST。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM