2

所以我得到Unauthorized error了http客户端的授权。我试图访问的网站具有NTLM身份验证。如果有人可以帮助解决这个问题,将不胜感激。

public class ClientAuthentication {

    public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();

        try {
            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope("website", 80),
                    new UsernamePasswordCredentials("username", "password"));

            HttpGet httpget = new HttpGet("http://cdg5.intranet.bell.ca/BlackFoot/Ont/");

            System.out.println("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());

            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
            }
            EntityUtils.consume(entity);



   } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
}

这是我得到的结果

"执行requestGET http://cdg5.intranet.bell.ca/BlackFoot/Ont/HTTP/1.1

HTTP/1.1 401 未经授权的响应内容长度:1656"

4

0 回答 0