Search code examples
phpsymfonyhttpproxyheader

Which HTTP headers needed for connection throw Proxy with Basic Authentication?


$curlClient = new HttpBrowser(HttpClient::create());
$url        = 'http://example.com';

$response   = $curlClient->request('GET', $url, [
            'headers' => [
                'Proxy' => '10.10.10.10:3128',
                'Proxy-Authorization' => 'Basic user:pass'
            ],
        ]);

I try to connect to example.com via proxy with Basic authentication.

Similar command in Curl looks like

curl -x 10.10.10.10:3128 --proxy-user user:pass -i http://example.com

What headers do I need to send ?


Solution

  • Proxy server in Symfony 5 should be configured just adding parameter proxy with correct Optional (Proxy user, proxy password), proxy IP, proxy port

            $curlClient     = new HttpBrowser(HttpClient::create(
            [
                'proxy' => 'http://proxy_username:proxy_password@proxy_ip:proxy_port'
            ]
        ));
    $url            = 'http://example.com';
    
    $response       = $curlClient->request('GET', $url);