无法通过代理隧道。代理返回“HTTP / 1.1 503服务不可用”

时间:2017-06-02 11:42:14

标签: java proxy

这是我的HTTPGet方法代码。但我得到了以下错误。

  

回应代码:503   线程“main”中的异常java.io.IOException:无法通过代理进行隧道传输。代理返回“HTTP / 1.1 503服务不可用”

我的代码是

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

尝试设置

System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

通过在另一个问题句柄中查看解决方案,在代码中

。但它仍然显示相同的错误。

任何替代解决方案?

0 个答案:

没有答案