Laravel - Guzzle 7:如何在 laravel 中有效 url?
Laravel - Guzzle 7 : How get effective url in laravel?
我想从用户那里得到一个 link 并检查它,如果它重定向,我们取最后一个 url(最终重定向 url)
例如,如果 links : goo.gl/test/123 重定向到 google.com ,我们将 http://google.com
在 Guzlle 的旧版本中我们可以获得有效 url ,但在版本 7 中我没有找到任何方法来获得这个
嗨
你可以做某事
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'http://test.com');
如果您想了解更多关于“track_redirects”的信息,请查看 this link
重定向列表的写答案/只有一个 url :
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'shorturl.at/jvOS5');
$lastRedirect = $response->getHeaderLine('X-Guzzle-Redirect-History');
更多文档:https://docs.guzzlephp.org/en/7.0/faq.html?highlight=redirected#how-can-i-track-redirected-requests
我想从用户那里得到一个 link 并检查它,如果它重定向,我们取最后一个 url(最终重定向 url) 例如,如果 links : goo.gl/test/123 重定向到 google.com ,我们将 http://google.com 在 Guzlle 的旧版本中我们可以获得有效 url ,但在版本 7 中我没有找到任何方法来获得这个
嗨
你可以做某事
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'http://test.com');
如果您想了解更多关于“track_redirects”的信息,请查看 this link
重定向列表的写答案/只有一个 url :
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'shorturl.at/jvOS5');
$lastRedirect = $response->getHeaderLine('X-Guzzle-Redirect-History');
更多文档:https://docs.guzzlephp.org/en/7.0/faq.html?highlight=redirected#how-can-i-track-redirected-requests