Java 为什么HttpURLConnection在401响应后重试连接时不重新发送PUT内容?

Java 为什么HttpURLConnection在401响应后重试连接时不重新发送PUT内容?,java,android,httpurlconnection,Java,Android,Httpurlconnection,Android上的HttpURLConnection(API级别7)有点奇怪。我使用的是基本身份验证,使用默认身份验证程序进行设置,如下所示: Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toC

Android上的HttpURLConnection(API级别7)有点奇怪。我使用的是基本身份验证,使用默认身份验证程序进行设置,如下所示:

Authenticator.setDefault(new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password.toCharArray());
    }
});
我提出的标准要求如下:

public InputStream put(String type, String name, String xml){

    try{
        String urlString = this.getURLString(type,name);
        URL url = new URL(urlString);
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("PUT");
        OutputStreamWriter out = new OutputStreamWriter(
            urlConnection.getOutputStream());
        out.write(xml);
        out.close();
        urlConnection.getInputStream();
        urlConnection.disconnect();
        return null;

    }
    catch(Exception e){
        Log.e(TAG,e.getMessage());
        return urlConnection.getErrorStream();
    }
}
数据包跟踪显示内容正在与HTTP请求一起发送。然后,我从服务器接收到401未经授权的响应,并重新发送响应。这一次,凭据将按照我的预期发送,但内容将不再发送。现在它是一个内容长度为0的空白PUT请求

以前有人见过这个吗?我该如何修复它

谢谢,
Sean最终解决了这个问题,没有使用验证器,而是将基本授权头手动添加到HttpURLConnection