java - How do I configure apache httpcore 4 to use a proxy? -
I'm trying to use the latest (4.0.1) Apache HTTP Core Components library. However, my web browser goes through a proxy - assuming this is myproxy.com: 9191. Can anyone provide a sample code to use it as a proxy to obtain any simple HTTP?
I tried to add the following at the beginning of my code, but there is no happiness:
ProxySelector.setDefault (new proxy selector () {public list & lt; Proxy Select (URI uri) {Proxy Proxy = New Proxy (Proxy. HTTP, New InetSocketAddress ("myproxy.com", 9191); Return Arrays.asList (New Proxy [] {Proxy}}) }} Public Zero Connectfail (URI Yuri, Socket Address, IOexpress ioe) {io.printStackTrace ();}}); In the absence of an answer, this is what I have found. First, for this type of thing, you do not want to use only the http core library, you also want to use it, make sure you download both from the download page.
Second, use this code:
DefaultHttpClient httpclient = new DefaultHttpClient (); HttpHost Proxy = New HTTPHOS ("myproxy.com", 911-191); Httpclient.getCredentialsProvider () SetCredentials (New AuthScope (PROXY, PROXY_PORT), New username password certificate ("username", "password")); Httpclient.getParams () SetParameter (ConnRoutePNames.DEFAULT_PROXY, Proxy);
Comments
Post a Comment