If the raw response is in the form of a query string (e.g., key1=value1&key2=value2
), you can use PHP’s built-in parse_str()
function to convert it into an associative array.
use Illuminate\Support\Facades\Http;
$response = Http::post('https://api.example.com/endpoint', [
'key1' => 'value1',
'key2' => 'value2',
]);
$rawResponse = $response->body(); // Get the raw response
$parsedResponse = [];
// Parse the query string into an associative array
parse_str($rawResponse, $parsedResponse);
dd($parsedResponse); // Now you can work with the associative array