With the Symfony Http Client I create a HTTP request like this:
$client = HttpClient::create();
$response = $client->request('GET', 'www.mypage.com', [
'auth_basic' => ['user', '123'],
]);
dump($response);
The output is:
Symfony\Component\HttpClient\Response\CurlResponse {#1117 ▼
response_headers: []
http_code: 0
error: null
url: www.something.com
....
Now I try to output the url
of that response:
dump($response->getContent());
But the output is null
.
How can I get as an output the url www.something.com
?
All the
HttpClient
responses implement theResponseInterface
, defined on Symfony Contracts.That interface declares a
getInfo()
method, as shown here.This method returns an array, and the effective URL of the response is stored at
url
key.Not that if the request went through one or more HTTP redirects, the final resolved URL may not be the same as the one originally requested.