Php 来自HTTP上响应的URI

Php 来自HTTP上响应的URI,php,laravel,guzzle,Php,Laravel,Guzzle,我需要从GuzzleHTTP的Response中获取URI,目前正在使用getAsync,同时处理至少50个项目,并且需要一种方法来获取我从guzzle客户端使用的URI $groups->each(函数($group){ $promises=$group->map(函数($lead,$index){ $client=新客户端(['http_errors'=>false]); 返回$client->getAsync($lead->website[ 'timeout'=>5,//响应超时 “连接超

我需要从
GuzzleHTTP
Response
中获取
URI
,目前正在使用
getAsync
,同时处理至少50个项目,并且需要一种方法来获取我从guzzle
客户端使用的
URI

$groups->each(函数($group){
$promises=$group->map(函数($lead,$index){
$client=新客户端(['http_errors'=>false]);
返回$client->getAsync($lead->website[
'timeout'=>5,//响应超时
“连接超时”=>5,//连接超时
]); 
})->toArray();
结算($promises)->then(函数($results){
$collections=收集($results);
$completed=$collections->where('state','completed')->all();
})->等待();
});
似乎
请求
有这个
getUri
方法,但是
响应
在接口或类以及文档中没有,也找不到,希望有人能帮助


编辑:尝试了
getEffectiveUrl
,但这只适用于Guzzle 5,目前使用的是6

这是针对Guzzle 5的

在响应中,您没有getUri方法,因为只有请求具有此方法

如果发生重定向或其他情况,您可以使用以下方法获取响应url

$response = GuzzleHttp\get('http://httpbin.org/get');
echo $response->getEffectiveUrl();
// http://httpbin.org/get

$response = GuzzleHttp\get('http://httpbin.org/redirect-to?url=http://www.google.com');
echo $response->getEffectiveUrl();
// http://www.google.com

狂饮6

将6.1溶液直接从罐中灌入

归功于


嘿,谢谢你的回答。请看编辑的行。。目前正在使用Guzzle 6这对Guzzle 5很有帮助*
use GuzzleHttp\Client;
use GuzzleHttp\TransferStats;

$client = new Client;

$client->get('http://some.site.com', [
    'query'   => ['get' => 'params'],
    'on_stats' => function (TransferStats $stats) use (&$url) {
        $url = $stats->getEffectiveUri();
    }
])->getBody()->getContents();

echo $url; // http://some.site.com?get=params