0

This is a follow up in regards to my question about removing the expect headers.

I have a mock soap server imitating the external endpoint. It was set up by using the default SoapServer of php:

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

which worked before, once I remove the expect header in the client, I only get an empty response back, no matter the request making my acceptance fail:

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

(The "" is placeholder for empty text.)

Community
  • 1
  • 1
k0pernikus
  • 60,309
  • 67
  • 216
  • 347

1 Answers1

0

The note, even though downvoted, by king maxemilian on php.net pointed me in the right direction. They wrote:

Sometime, it happens that PHP does not detect anything in $HTTP_RAW_POST_DATA.

To solve this problem and make it work in any case:

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

I simplified this for my mock soap server to

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

$server->handle(findSoapRequest());

While this works for me, I have no clue as to why it's happen.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347