Goutte Access Guzzle Response

I am trying to access a Guzzle Response object from Goutte. Because this object has good methods that I want to use. For example, getEffectiveUrl.

As far as I can see, there is no way to do this without breaking the code.

Or without access to the response object, is there a way to get the last redirected url froum goutte?

+4
source share
1 answer

A bit late, but:

If you are only interested in getting the URL you were redirected to, you can simply do

$client = new Goutte\Client();
$crawler = $client->request('GET', 'http://www.example.com');
$url = $client->getHistory()->current()->getUri();

EDIT:

Goutte . , , createResponse() GuzzleResponse

namespace Your\Name\Space;

class Client extends \Goutte\Client
{
    protected $guzzleResponse;

    protected function createResponse(\Guzzle\Http\Message\Response $response)
    {
        $this->guzzleResponse = $response;

        return parent::createResponse($response);
    }

    /**
     * @return \Guzzle\Http\Message\Response
     */
    public function getGuzzleResponse()
    {
        return $this->guzzleResponse;
    }
}

$client = new Your\Name\Space\Client();
$crawler = $client->request('GET', 'http://localhost/redirect');
$response = $client->getGuzzleResponse();

echo $response->getEffectiveUrl();
+11

All Articles