0
votes

Using laravel 5.2 I tried the folowing code:

$xml =
"<BALANCE>
<Userid>myuserid</Userid>
<Loginkey>myloginkey</Loginkey>
<Transactionid>mytransactionid</Transactionid>
</BALANCE>";

$request = $client->request('POST', 'serveraddress:serverport/servicename/webservice.php',['Content-Type' => 'text/xml; charset=UTF8'],$xml);

var_dump($request->getBody());

And I get the following response:

object(GuzzleHttp\Psr7\Stream)#171 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private]=> resource(231) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private]=> NULL ["seekable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private]=> string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=> array(0) { } }

According to the provider the request and response on the server are ok.

How can I use the xml response? In other words, how can I use the psr7 object or stream, so I can display meaningfull info?

Answers I read which didn't help me "yet" (either don't know what to do with the info given or the info doesn't apply to my situation);

  1. https://stackoverflow.com/a/32512634/3664960 -> I'm using 6 and I don't know if the answer sugests going to the older version
  2. https://stackoverflow.com/a/30549372/3664960 when using the first option to put string in front the result is

string(1) " "

  1. https://stackoverflow.com/a/37258804/3664960 -> json_decode

NULL

  1. https://stackoverflow.com/a/31791933/3664960

string(1) " "

5.https://stackoverflow.com/a/35632231/3664960

See my comments in the comments


What else can I try?


note:

I can read the headers and display them correctly!

1

1 Answers

0
votes

I think you simply get an empty answer from the server. Because your request is wrong.

Try this

$request = $client->request(
    'POST',
    'serveraddress:serverport/servicename/webservice.php',
    [
        'headers' => ['Content-Type' => 'text/xml; charset=UTF8'],
        'body' => $xml
    ]
);

instead of the original request.

Pay attention to the options. Client::request() doesn't have a fourth parameter for the body, it should be passed as an option.