1 回答

TA貢獻1850條經驗 獲得超11個贊
這是給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
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 關注
- 163 瀏覽
添加回答
舉報