小编Pra*_*kta的帖子

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

这是我的 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); …
Run Code Online (Sandbox Code Playgroud)

java proxy

5
推荐指数
0
解决办法
6685
查看次数

标签 统计

java ×1

proxy ×1