0

我有这个身份验证器:

Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });

我用它来连接到一个站点:

Connection.Response res = Jsoup
                            .connect("https://somesite")
                            .execute();
                    Log.d("STATUSCODE", res.statusMessage());

我可以处理一切正常,除了登录错误。statusMessage ()总是说好的,即使登录凭据是错误的,而不是将状态码设置为 401,它只是抛出一个SocketTimeoutException。知道为什么吗?

4

1 回答 1

0

尝试设置timeout属性:

Connection.Response res = Jsoup
                        .connect("https://somesite")
                        .timeout(0)
                        .execute();
于 2016-04-08T06:59:57.660 回答