Java HttpURLConnection的验证器在Froyo中工作,但在IceCreamSandwich中不工作

Java HttpURLConnection的验证器在Froyo中工作,但在IceCreamSandwich中不工作,java,android,http,android-4.0-ice-cream-sandwich,Java,Android,Http,Android 4.0 Ice Cream Sandwich,我把这段代码放在一个可运行的,在Froyo上的程序里,一切都很完美。但在ICS上,它说它确实连接,但给了我一个文件未找到错误,并返回-1作为文件大小 ICS上不需要身份验证的文件没有问题 在ICS上有不同的身份验证方法吗?还是我遗漏了一些ICS HttpURLConnection的细节 Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(

我把这段代码放在一个可运行的,在Froyo上的程序里,一切都很完美。但在ICS上,它说它确实连接,但给了我一个文件未找到错误,并返回-1作为文件大小

ICS上不需要身份验证的文件没有问题

在ICS上有不同的身份验证方法吗?还是我遗漏了一些ICS HttpURLConnection的细节

Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,pass);
                    }
                });
URL url = new URL(URLString);

HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();//connection says that it is connected
final int filesize = c.getContentLength();//file size is -1 when using ICS
c.disconnect();
另外,我在验证Froyo上的https url时遇到了问题,这是目前的第二个问题

如果可以的话,谢谢你的帮助

我已经离开一段时间了,但这就是我现在使用的。它确实与ICS一起工作,我目前没有与Froyo一起测试,所以不能肯定它是否与这两个都工作

    private void setAuthenticationCredentials(final String username, final String password) {
            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password
                            .toCharArray());

我一直在使用
HttpURLConnection.setRequestProperty()
验证我的请求,如下所示:

String unencoded = username + ":" + password;
String encoded = Base64.encodeToString(unencoded.getBytes(), Base64.DEFAULT);
Log.d(getClass().getName(), "encoded: " + encoded);
// Attach as authentication header.
connection.setRequestProperty("Authorization", "Basic " + encoded);

然而,这似乎有相反的问题。它适用于3.0及更高版本,但不适用于2.3.4及更低版本(服务器显然会发送一个400,尽管请求不在服务器日志中)。请告诉我您是否能使用/已经使用,我将非常感谢您提供的信息。

谢谢。我现在也在使用
验证器
,没有发现任何问题。这绝对是正确的方法。