This is my code for HTTPGet method. But I am getting following error.
Response Code : 503 Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable"
My code is
Proxy objProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
"proxyname", port_no));
String url = "any url";
URL obj = new URL(url);
System.out.println("URL" + obj.toString());
HttpURLConnection con = (HttpURLConnection) obj.openConnection(objProxy);
// optional default is GET
con.setRequestMethod("GET");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password"
.toCharArray());
}
});
System.out.println("Proxy Used: " + con.usingProxy());
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
Tried setting
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
in the code by seeing a solution in another question handle. But still it shows the same error.
Any alternate solution?