PHP Curl proxy option in Laravel Http Facade

Viewed 1061

I am using Laravel's Http facade to make requests such as

Http::withHeaders(['user-agent' => 'My User agent'])->retry(3, 500)->get('https://example.com')->body();

And need to use proxy, which as per proxy provider's example should be set like this in case of PHP's curl

curl_setopt($curl, CURLOPT_PROXY, 'aaa');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'xxx:xxx');

Can these proxy options be somehow set with Laravel's Http class above?

1 Answers

Http Facade is allowed you to use guzzle options, and guzzle has proxy option. So based on your code, you need to do like this:

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();
Related