Laravel Http Facade中的PHP Curl代理选项
我正在使用Laravel的Http facade发出如下请求Laravel Http Facade中的PHP Curl代理选项,php,laravel,curl,Php,Laravel,Curl,我正在使用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,
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也允许您使用。因此,根据您的代码,您需要这样做:
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();