Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.net.Authenticator:java.net.ProtocolException:服务器重定向次数过多(20次)_Java_Http Proxy - Fatal编程技术网

java.net.Authenticator:java.net.ProtocolException:服务器重定向次数过多(20次)

java.net.Authenticator:java.net.ProtocolException:服务器重定向次数过多(20次),java,http-proxy,Java,Http Proxy,我们通过weblogic服务器(node1/node2)上的java独立示例代码使用代理设置调用URL。 这段代码在节点1上运行良好,但在节点2服务器上不运行相同的代码。 我们已经检查了代理设置和凭据,但仍然出现以下错误: java.net.ProtocolException: Server redirected too many times (20) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(

我们通过weblogic服务器(node1/node2)上的java独立示例代码使用代理设置调用URL。 这段代码在节点1上运行良好,但在节点2服务器上不运行相同的代码。 我们已经检查了代理设置和凭据,但仍然出现以下错误:

 java.net.ProtocolException: Server redirected too many  times (20)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
        at ProxyCode.start2(ProxyCode.java:54)
        at ProxyCode.main(ProxyCode.java:23)
Exception in thread "Main Thread" java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:61)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
        at ProxyCode.readFromInputStream(ProxyCode.java:65)
        at ProxyCode.start2(ProxyCode.java:59)
        at ProxyCode.main(ProxyCode.java:22)
主要类别:

    String url = "http://www.oracle.com/technetwork/java/readme-2-149793.txt";
    String proxy = "proxyserver";
    String port = "8080";
    String username = "username";
    String password = "password";
    Authenticator.setDefault(new SimpleAuthenticator(username,password));

    URL server = null;
    try {

            CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
            server = new URL(url);
    }
    catch (MalformedURLException e) {
            e.printStackTrace();
    }

Properties systemProperties = System.getProperties();
    systemProperties.setProperty("http.proxyHost", proxy);
    systemProperties.setProperty("http.proxyPort", port);

    InputStream in = null;
    URLConnection connection = null;

    try {
            connection = (URLConnection) server.openConnection();
            connection.connect();
            in = connection.getInputStream();
    }
    catch (IOException e) {
            e.printStackTrace();
    }
            System.out.println(readFromInputStream(in));
    }

    public static String readFromInputStream(InputStream in) {
            StringBuffer strBuf = new StringBuffer();
            char ac[];
            BufferedReader buf = new BufferedReader(new InputStreamReader(in));

      try 
     {
            while (buf.ready()) {
                    ac = new char[10000];
                    buf.read(ac);
                    strBuf.append(ac);
     }
            buf.close();
    }
    catch (IOException e) {
            e.printStackTrace();
    }
几个月以来,我们一直陷于此,无法在任何地方获得任何有用的信息。
请提供帮助。谢谢

如果您提供了错误的凭据(用户名或密码),则会出现此错误。 这发生在我的一个基于Glassfish的web应用程序上。然而,我期待着401的回应


我认为,身份验证程序多次尝试相同的凭据。

发现了这个未解决的问题,但似乎仍未解决。您的用户没有访问权限,但不会再次提示

最新消息:该问题还有另一个问题有待解决-这显然是预期的行为和后果

“为了克服这一点,您必须执行
Authenticator::getPasswordAuthentication
需要提供一种方法 如果初始身份验证尝试失败,请收集正确的密码 不成功。”


查看罚单或了解更多信息。

您是否使用Firebug或chrome/IE开发者工具查看进行了哪些重定向?有时,这可能会给出一个关于发生了什么的线索。我正在unix box上运行它。使用CURL进行测试的结果是肯定的。它是有效的。但是从JAVA代码调用URL不起作用。我仍然认为查看重定向是如何进行的会有所帮助。还有别的选择吗?
    String url = "http://www.oracle.com/technetwork/java/readme-2-149793.txt";
    String proxy = "proxyserver";
    String port = "8080";
    String username = "username";
    String password = "password";
    Authenticator.setDefault(new SimpleAuthenticator(username,password));

    URL server = null;
    try {

            CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
            server = new URL(url);
    }
    catch (MalformedURLException e) {
            e.printStackTrace();
    }

Properties systemProperties = System.getProperties();
    systemProperties.setProperty("http.proxyHost", proxy);
    systemProperties.setProperty("http.proxyPort", port);

    InputStream in = null;
    URLConnection connection = null;

    try {
            connection = (URLConnection) server.openConnection();
            connection.connect();
            in = connection.getInputStream();
    }
    catch (IOException e) {
            e.printStackTrace();
    }
            System.out.println(readFromInputStream(in));
    }

    public static String readFromInputStream(InputStream in) {
            StringBuffer strBuf = new StringBuffer();
            char ac[];
            BufferedReader buf = new BufferedReader(new InputStreamReader(in));

      try 
     {
            while (buf.ready()) {
                    ac = new char[10000];
                    buf.read(ac);
                    strBuf.append(ac);
     }
            buf.close();
    }
    catch (IOException e) {
            e.printStackTrace();
    }