使用HTTPCLIENT进行身份验证后未经授权的连接

时间:2013-02-13 18:26:54

标签: java http

所以我在使用http客户端授权后获得Unauthorized error。我尝试访问的网站具有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“

0 个答案:

没有答案