1 回答

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
這是給guzzle 5用的
在響應(yīng)中,您沒(méi)有 getUri 方法,因?yàn)橹挥姓?qǐng)求有此方法。
如果發(fā)生重定向或發(fā)生某些情況,您可以使用以下方法獲取響應(yīng) 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
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
- 1 回答
- 0 關(guān)注
- 162 瀏覽
添加回答
舉報(bào)