Php Laravel-Guzzle 7:如何在Laravel中获得有效的url?
我想从用户那里得到一个链接并检查它,如果它重定向,我们将使用最后一个url(最终重定向的url) 例如,如果这个链接:goo.gl/test/123重定向到google.com,我们将Php Laravel-Guzzle 7:如何在Laravel中获得有效的url?,php,laravel,guzzle,Php,Laravel,Guzzle,我想从用户那里得到一个链接并检查它,如果它重定向,我们将使用最后一个url(最终重定向的url) 例如,如果这个链接:goo.gl/test/123重定向到google.com,我们将 在Guzlle的旧版本中,我们可以获得有效的url,但在第7版中,我没有找到任何方法来获得此链接 $client=new\GuzzleHttp\client(['allow\u redirects'=>['track\u redirects'=>true]]); $response=$client->reques
在Guzlle的旧版本中,我们可以获得有效的url,但在第7版中,我没有找到任何方法来获得此链接
$client=new\GuzzleHttp\client(['allow\u redirects'=>['track\u redirects'=>true]]);
$response=$client->request('GET','http://test.com');
如果你想了解更多关于“跟踪重定向”的信息,请查看嗨
你可以做类似的事情
$client=new\GuzzleHttp\client(['allow\u redirects'=>['track\u redirects'=>true]]);
$response=$client->request('GET','http://test.com');
如果您想了解更多关于“跟踪重定向”的信息,请查看重定向/仅一个url列表的写入答案:
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'shorturl.at/jvOS5');
$lastRedirect = $response->getHeaderLine('X-Guzzle-Redirect-History');
文档中的更多信息:重定向/仅一个url列表的书面答案:
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'shorturl.at/jvOS5');
$lastRedirect = $response->getHeaderLine('X-Guzzle-Redirect-History');
更多信息请参阅文件: