I have code that needs to make an outbound http connection. However, I am behind a proxy.
I have seen examples of how to set the proxy parameters, but none of which allow me to specify my username and password.
Has anyone got an example to help me out?
Here is a reference on configuration proxy information for any Java app. If you are running your app from Eclipse, you will want to set these in your launch configuration.
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("30.40.50.60", 8080));
URL url = new URL("http://www.somewebsite.com");
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
I ended up using Apache HttpClient - http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
You can find this under Run->Run Configurations or Run->Debug Configurations, under the “Target” tab. You’re looking for the “Additional Emulator Command Line Options” box. In my case, the full string I used was -http-proxy http://username:password@10.0.0.1:3128 where username is my proxy login, password is my proxy password, 10.0.0.1 is my proxy IP address, 3128 is the port.
emulator settings from within the emulator. I have no idea why this is necessary but it didn’t work without this change. Once you launch the emulator, go to Settings->Wireless & Networks->Mobile Networks->Access Point Names->TelKila and set “Proxy” and “Port” to match the settings above