How can I set the http proxy in eclipse?

2019-05-31 15:38发布

问题:

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?

回答1:

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



回答2:

  1. [Windows] -> [Preferences] -> [General] -> [Network Connections]
  2. Set Active Provider to "Manual"
  3. Select protocol (HTTP)
  4. Click Edit
  5. Click "Requires Authentication"
  6. Provide creds


回答3:

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);


回答4:

I ended up using Apache HttpClient - http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientProxyAuthentication.java



回答5:

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