Proxy settings in a Java program

I am trying to connect to a web service with a client generated from wsdl through a java program in eclipse. I pass my request through a proxy server. But it seems that the request does not pass. The same proxy settings work on SoapUI. The following are the system properties set by me.

Properties props= new Properties(System.getProperties()); props.put("http.proxySet", "true"); props.put("http.proxyHost", "10.xxx"); props.put("http.proxyPort", "80"); props.put("http.proxyUser","domainName\\xxx"); props.put("http.proxyPassword","xxx"); Properties newprops = new Properties(props); 

The Java program throws an exception like java.net.UnknownHostException:

What am I missing?

+9
java proxy
source share
9 answers
 java -Dhttp.proxyHost=proxyhostURL -Dhttp.proxyPort=proxyPortNumber -Dhttp.proxyUser=someUserName -Dhttp.proxyPassword=somePassword javaClassToRun 

http://i4t.org/2007/05/04/java-http-proxy-settings/

+9
source share

if you connect webservice using HTTPS, then the proxy property for installation is

 https.proxyHost https.proxyPort 

( http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html )

+5
source share

I use the following code (and it works):

  String host = "10.xxx"; String port = "80"; System.out.println("Using proxy: " + host + ":" + port); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port); System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1"); 
+4
source share

In addition to setting system properties, use java.net.Authenticator to set the proxy configuration.

 final String authUser = "user"; final String authPassword = "password"; Authenticator.setDefault( new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( authUser, authPassword.toCharArray()); } } ); System.setProperty("http.proxyUser", authUser); System.setProperty("http.proxyPassword", authPassword); 
+2
source share

I managed to get through the proxy using the following code snippet.

Added some new lines to Snehasish code

 final String authUser = "username"; final String authPassword = "password"; Authenticator.setDefault( new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( authUser, authPassword.toCharArray()); } } ); url = new URL("http://www.somewebsite.com/sendmyrequest"); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setFollowRedirects(true); System.getProperties().put("http.proxyHost", "proxy.xyz.com"); System.getProperties().put("http.proxyPort", "portNumber"); System.setProperty("http.proxyUser", authUser); System.setProperty("http.proxyPassword", authPassword); System.getProperties().put("http.proxySet", "true"); 
+1
source share

You can install Proxy using System.setProperty()

 System.setProperty("http.proxyHost","122.183.139.107"); System.setProperty("http.proxyPort","8080"); 

and if you want to delete

 System.setProperty("http.proxyHost",""); System.setProperty("http.proxyPort",""); 
+1
source share

I have the same problem. Just the following code works for me to configure the proxy.

 System.setProperty("java.net.useSystemProxies", "true"); 
+1
source share

There is no such property as http.proxySet .

You need to set other properties before using any HTTP URLs, and then changing them has no effect.

If you need to change proxies dynamically, see Java.net.Proxy.

'Open text join?' means exactly what is written: you are using SSL for a purpose other than SSL, possibly in plain text.

0
source share

In the eclipse IDE, go to Window-> Preferences. There, write proxies in the small box on the left. You should see Network connections , enter the proxy settings for the requests (HTTP should be sufficient), which you will use. I believe that this will solve your problem without installing a proxy inside the code itself.

-3
source share

All Articles