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");
jai kiran
source share