Skip to content
Advertisement

How can I access the URL of a Symfony Http Client response?

With the Symfony Http Client I create a HTTP request like this:

JavaScript

The output is:

JavaScript

Now I try to output the url of that response:

JavaScript

But the output is null.

How can I get as an output the url www.something.com?

Advertisement

Answer

All the HttpClient responses implement the ResponseInterface, 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.

JavaScript

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement