为什么我的模拟Soap Server只返回空字符串?

时间:2016-11-23 11:32:13

标签: php soap soapserver

这是关于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);
之前有效的

,一旦我删除了客户端中的expect标头,我只会得到一个空的响应,无论请求让我的接受失败:

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
""

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

1 个答案:

答案 0 :(得分:0)

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());

虽然这对我有用,但我不清楚它为什么会发生。

相关问题