I’m using Symfony HttpClient Component, it became necessary to use it with a proxy. Open proxy with the port, I can easily configure with the default configuration when instantiating CurlHttpClient class, but I can’t set username and password for private proxy
Example of default configuration:
use SymfonyComponentHttpClientCurlHttpClient; $httpClient = new CurlHttpClient([ 'http_version' => '2.0', 'proxy' => 'x.xx.xxx.xxx:8000', ]);
I try to add additional configuration on the extra options, and try other combinations, but can’t find the right way.
with plain PHP and cURL everything works fine.
Please, help me, configure the Symfony HttpClient Component with a private proxy.
Advertisement
Answer
You need to specify protocol (e.g. socks5
, socks4
etc)
use SymfonyComponentHttpClientCurlHttpClient; $httpClient = new CurlHttpClient([ 'http_version' => '2.0', 'proxy' => 'socks5://username:password@127.0.0.1:9999', ]); dump($httpClient->request('GET', 'https://api.ipify.org?format=json')->getContent());