我正在使用 Laravel 的 Http facade 来发出如下请求
Http::withHeaders(['user-agent' => 'My User agent'])->retry(3, 500)->get('https://example.com')->body();
并且需要使用代理,根据代理提供商的示例,在 PHP 的 curl 情况下应该这样设置
curl_setopt($curl, CURLOPT_PROXY, 'aaa');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'xxx:xxx');
这些代理选项可以通过 Laravel 上面的 Http 类以某种方式设置吗?
最佳答案
允许您使用 Http Facade guzzle options , guzzle 有 proxy option .因此,根据您的代码,您需要这样做:
Http::withHeaders(['user-agent' => 'My User agent'])
->withOptions(['proxy' => 'http://username:password@192.168.16.1:8080'])
->retry(3, 500)
->get('https://example.com')
->body();
关于Laravel Http Facade 中的 PHP Curl 代理选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66700709/