【问题标题】:Why is my mock Soap Server only returning empty string?为什么我的模拟 Soap 服务器只返回空字符串?
【发布时间】:2016-11-23 11:32:12
【问题描述】:

这是关于我关于 removing the expect headers 的问题的跟进。

我有一个模拟外部端点的模拟肥皂服务器。它是使用php的默认SoapServer设置的:

$server = new SoapServer('http://externalapi.foo/the_wsdl.xml');
$server->setClass(ExternalApi::class);
$server->handle($HTTP_RAW_POST_DATA);

以前有效,一旦我删除客户端中的期望标头,我只会得到一个空响应,无论请求使我的接受失败:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/html
Date: Wed, 23 Nov 2016 11:18:40 GMT
Server: nginx/1.11.6
Transfer-Encoding: chunked
X-Powered-By: HHVM/3.15.3
""

"" 是空文本的占位符。)

【问题讨论】:

    标签: php soap soapserver


    【解决方案1】:

    king maxemilian on php.net 的注释虽然被否决了,却为我指明了正确的方向。他们写道:

    有时,PHP 碰巧在 $HTTP_RAW_POST_DATA.

    为了解决这个问题并让它在任何情况下都能正常工作:

    function soaputils_autoFindSoapRequest()    {
        global $HTTP_RAW_POST_DATA;
    
        if($HTTP_RAW_POST_DATA)
            return $HTTP_RAW_POST_DATA;
    
        $f = file("php://input");
        return implode(" ", $f);
    }
    
    $server = new SoapServer($wsdl);
    $server->setClass($MyClass);
    
    $server->handle(soaputils_autoFindSoapRequest());
    

    我将我的模拟肥皂服务器简化为

    /**
     * @return string
     */
    function findSoapRequest()    {
        $f = file("php://input");
        return implode(" ", $f);
    }
    
    $server->handle(findSoapRequest());
    

    虽然这对我有用,但我不知道为什么会这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      相关资源
      最近更新 更多