iamzouz
iamzouz

Reputation: 109

How to set proxy in Http request in Laravel 7?

Below is my successful HTTP request on DEV environment:

$response = Http::withHeaders([
                        'Content-Type' => 'application/json',
                        'Accept' => 'application/json'
                    ])
                    ->withToken('xxxxxxxxxxxxxx')
                    ->post('https://xxxxxxxxx.com/v0.1/messages/', [
                        'from' => [
                            'type' => 'xxxx',
                            'number' => 'xxxxxxxx',

                        ],
                        'to' => [
                            'type' => 'xxxxx',
                            'number' => 'xxxxxx',
                        ],
                        'message' => [
                            'content' => [
                                'type' => 'text',
                                'text' => 'test message from laravel'
                            ]
                        ]
                    ]);

But on production its mandatory to add a proxy to the request.

Anyone have any idea how to pass a proxy with the request above ? Thank you in advance.

Upvotes: 3

Views: 12655

Answers (1)

dannepanne
dannepanne

Reputation: 427

You can specify Guzzle options using the withOptions method.

Hence:

$response = Http::withOptions([
   'proxy' => 'http://username:[email protected]:7000'
])->withHeaders( ...

Upvotes: 6

Related Questions