Reputation: 375
I have to consume an old Web API in Laravel.
Response body looks like this:
TRANSACTION_ID: KJASDFYDSF^SDFHJSD/2236
STATUS: OK
DATE: 01/03/18
How can I convert the response into Array using Guzzle 6?
Upvotes: 0
Views: 1385
Reputation: 375
Here is the solution with parsing response:
private function parseResponse(\GuzzleHttp\Psr7\Response $response) {
$body = $response->getBody();
$body->rewind();
$content = (string) $body->getContents();
$lines = explode(PHP_EOL, $content);
$result = [];
foreach ($lines as $line) {
$chunks = explode(':', $line);
$result[trim($chunks[0])] = trim($chunks[1]);
}
return $result;
}
Upvotes: 2