php – 来自Goutte的Guzzle回应
发布时间:2020-05-25 08:51:27 所属栏目:PHP 来源:互联网
导读:我正在尝试从Goutte访问Guzzle Response对象.因为该对象具有我想要使用的好方法.以getEffectiveUrl为例. 据我所知,如果不破解代码,就无法做到这一点. 或者没有访问响应对象,有没有办法获取最后重定向的URL froum goutte? 有点晚了,但是: 如果您只想获取上次
|
我正在尝试从Goutte访问Guzzle Response对象.因为该对象具有我想要使用的好方法.以getEffectiveUrl为例. 据我所知,如果不破解代码,就无法做到这一点. 或者没有访问响应对象,有没有办法获取最后重定向的URL froum goutte? 有点晚了,但是:如果您只想获取上次重定向到的URL,您可以这样做 $client = new GoutteClient();
$crawler = $client->request('GET','http://www.example.com');
$url = $client->getHistory()->current()->getUri();
编辑: 但是,扩展Goutte以满足您的需求是相当容易的.您所需要的只是覆盖createResponse()方法并存储GuzzleResponse namespace YourNameSpace;
class Client extends GoutteClient
{
protected $guzzleResponse;
protected function createResponse(GuzzleHttpMessageResponse $response)
{
$this->guzzleResponse = $response;
return parent::createResponse($response);
}
/**
* @return GuzzleHttpMessageResponse
*/
public function getGuzzleResponse()
{
return $this->guzzleResponse;
}
}
然后,您可以根据需要访问响应对象 $client = new YourNameSpaceClient();
$crawler = $client->request('GET','http://localhost/redirect');
$response = $client->getGuzzleResponse();
echo $response->getEffectiveUrl(); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
