ProxySelector changes URL's scheme from https:// to socket://

前端 未结 2 1004
刺人心
刺人心 2021-01-15 09:03

I need to access Facebook but all outgoing communication is blocked on our server so I have to use proxy.

I initialize proxies with:

ProxySelector.se         


        
2条回答
  •  生来不讨喜
    2021-01-15 09:47

    It's not the ProxySelector that changes the scheme, but the SocketFactory opening a Socket. If the SocketFactory is null a SOCKS socket will be created by default which only allows SOCKS proxies. I don't know anything about Sockets and cannot tell you if there's a way to make it work with HTTP proxies.

    But using another approach may help, since Apache HttpClient seems to have its own way to configure proxies.

    client.getHostConfiguration().setProxy(proxyHost, proxyPort);
    
    if (proxyUser != null) {
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), 
            new UsernamePasswordCredentials(proxyUser, proxyPassword));
    }
    

提交回复
热议问题