John
John

Reputation: 190

PHP Curl proxy option in Laravel Http Facade

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?

Upvotes: 3

Views: 3615

Answers (1)

Muhammad Dyas Yaskur
Muhammad Dyas Yaskur

Reputation: 8118

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:[email protected]:8080'])
->retry(3, 500)
->get('https://example.com')
->body();

Upvotes: 7

Related Questions