解决方案 »

  1.   

    看一下老外找到的变通方法,他说这是个 bug,不知道是不是真的:
    http://stackoverflow.com/questions/480895/reset-the-authenticator-credentials
      

  2.   

    http://stackoverflow.com/questions/480895/reset-the-authenticator-credentials
    用这个里面的处理方法还是没有解决,唉
      

  3.   

    你试过在每个连接之前用这个 set  MyCache() 么?这个 MyCache 实际上并不缓存,任何请求缓存的操作都被忽视。按这个人的经验,直接用 new AuthCacheImpl() 得到的依然不行,他是在 debug 时略有延迟的时候就正常,不是 debug 没有延迟立即完成的时候就不正常。https://community.oracle.com/thread/2152686?start=0&tstart=0static class MyCache implements sun.net.www.protocol.http.AuthCache{
         public void put(String pkey, sun.net.www.protocol.http.AuthCacheValue value){     }
         public sun.net.www.protocol.http.AuthCacheValue get(String pkey, String skey){
             return null;
         }
         public void remove(String pkey, sun.net.www.protocol.http.AuthCacheValue entry){     }
    }
    static{
        sun.net.www.protocol.http.AuthCacheValue.setAuthCache(new MyCache());}
      

  4.   

    这个 bug 2007年就提交了,但显示的是没处理。可能的理解就是:使用它默认的就是这个结果,如果我们想要自己的,可以提供自己的 AuthCache 实现方法。 http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6626700
      

  5.   

    最终放弃了使用Authenticator.setDefault(new BasicAuthenticator(username,password));
    换成以下代码实现,可以了
            String users = username+":"+password;
            httpsConn.addRequestProperty("Authorization", "Basic "+encode(users.getBytes()));再次感谢humanity 的帮忙,多谢