doutang7661 2014-03-13 10:25
浏览 112

当body不为空时,SoapClient在HTTP 500错误时返回空响应

So I'm trying to use SoapClient in PHP.

I have a class that works for most multiple services I'm working with but I have a problem.

One of services returns errors with HTTP 500 error, after the headers there is body. I know that using SoapUI. But in PHP I allways get an error and empty response.

Here is the response from SoapUI in raw form:

HTTP/1.1 500 Internal Server Error
Server: nginx/1.4.3
Date: Thu, 13 Mar 2014 10:17:49 GMT
Content-Type: multipart/related;start="<rootpart*e3413bc7-fd66-4420-8d19-c241a5e56173@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:e3413bc7-fd66-4420-8d19-c241a5e56173";start-info="text/xml"
Content-Length: 706
Connection: keep-alive

--uuid:e3413bc7-fd66-4420-8d19-c241a5e56173
Content-Id: <rootpart*e3413bc7-fd66-4420-8d19-c241a5e56173@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope" xmlns=""><faultcode>S:Server</faultcode>
<faultstring>Validation error</faultstring>
<detail><ns2:WsException xmlns:ns2="http://api.system.bacca.pl/">
<error>Kwota pożyczki netto nie może przekroczyć 5000zł</error>
</ns2:WsException></detail></S:Fault></S:Body></S:Envelope>
--uuid:e3413bc7-fd66-4420-8d19-c241a5e56173--

I have extended SoapClient to be able to work with singlepart multipart messages from Soap and here is the code:

class AdvancedSoapClient extends \SoapClient
{

    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
        // strip away everything but the xml.
        //http://www.w3.org/TR/soap12-mtom/#xop-serialization - strip mime multipart in onepart responses
        $resp = preg_replace('#^.*(<\?xml.*>)[^>]*$#s', '$1', $response);

        if($resp == null) {
            $xml = stripos($response, '<?xml');

            $resp = substr($response, $xml);
            $xmlEnd = stripos($resp, 'Envelope>');
            $resp = substr($resp,0,$xmlEnd+9);

            return $resp;
        }

        return $resp;
    }
}

I've tried to get content in this function but when problem occures $response is null...

Any ideas what I can do to retrive this response body?

@Edit: All I get from PHP is SoapFault exception:

message: Internal Server Error code: HTTP

@Edit2: Getting complete Raw response (headers & body) would be helpful enough too

  • 写回答

1条回答 默认 最新

  • doujiao6116 2014-04-08 12:28
    关注

    I share here my solution for this problem... It's not good, but it's best work-around I have.

    If exception occures I run class that executes same xml (I've saved request erlier) on the same url via cURL. cURL with proper configuration returns all data. Then I get the body and translate xml to object by my own.

    It's not good, optimal, or quick... but it's working...

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图