I have URL (http://forexample.com/index) where I send raw header:
header("HTTP/1.1 401 Some message");
With Guzzle I want to get this raw header message. Unfortunately after request is completed I can't find this message between headers:
$client = new GuzzleHttp\Client();
try {
$res = $client->post( 'http://forexample.com/index' );
} catch ( GuzzleHttp\Exception\BadResponseException $e ) {
// On HTTP response other than 200 Guzzle throws an exception
$res = $e->getResponse();
}
var_dump( $res->getHeaders() );
Let's say if I call this URL with native PHP function get_headers
:
var_dump( get_headers( 'http://forexample.com/index' ) );
I get all the headers. So any ideas?
$res->getReasonPhrase()
. However, the reason phrase is absolutely unnecessary if you have the status code. You shouldn't rely on the phrase, only on the status code, but your code is your code and you do what you deem fit. Good luck. – N.B.getReasonPhrase
returns "Unauthorized" message which is actually related to response code. But I need to get "Some message" message :) – Bounce