dongxiezhi0590 2019-06-05 14:43
浏览 3846
已采纳

如何在Symfony HttpClient组件的CurlHttpClient中添加具有IP /端口和用户名/密码的代理?

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 Symfony\Component\HttpClient\CurlHttpClient;

$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.

  • 写回答

2条回答 默认 最新

  • duanjunao9348 2019-06-06 10:47
    关注

    You need to specify protocol (e.g. socks5, socks4 etc)

    use Symfony\Component\HttpClient\CurlHttpClient;
    
    $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());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?