PHP Laravel Http Facade 中的 Curl 代理选项
PHP Curl proxy option in Laravel Http Facade
我正在使用 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 class 以某种方式设置吗?
允许您使用 Http Facade guzzle options, and guzzle has 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 来发出诸如
之类的请求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 class 以某种方式设置吗?
允许您使用 Http Facade guzzle options, and guzzle has 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();