5

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?

il_raffa
  • 5,090
  • 129
  • 31
  • 36
Prajakta
  • 51
  • 1
  • 3
  • See https://stackoverflow.com/questions/42904148/unable-to-tunnel-through-proxy-proxy-returns-http-1-1-503-service-unavailable/52643578 for a similar but much simpler caser – Jakub Holý Oct 04 '18 at 09:44

0 Answers0