2012-04-20 128 views
3

我使用JCIFS庫發現here在我的Android應用程序中使用NTLM身份驗證。該應用程序工作正常,當它只是去了一個網站和解析一個XML,但現在我添加了NTLM身份驗證它似乎沒有工作。任何人都可以從這段代碼中知道httpclient和inputstream之間的問題在哪裏?在Android應用NTLM身份驗證

DefaultHttpClient client = new DefaultHttpClient(); 
client.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); 
client.getCredentialsProvider().setCredentials(new AuthScope("http://www.musowls.org",80), 
new NTCredentials(username, password, null, "musschool")); 
HttpGet request = new HttpGet("http://www.musowls.org/assignments/assignmentsbystudentxml.aspx"); 
HttpResponse resp = client.execute(request); 
HttpEntity entity = resp.getEntity(); 
InputStream inputStream = entity.getContent(); 

回答

0

請嘗試下面的代碼,它可能會幫助你。

DefaultHttpClient httpclient = new DefaultHttpClient(); 
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); 

NTCredentials creds = new NTCredentials("user_name", "password", "", "http://www.musowls.org/"); 

httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); 
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 5000); 

HttpPost httppost = new HttpPost("http://www.musowls.org/assignments/assignmentsbystudentxml.aspx"); 
httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); 
HttpResponse response = httpclient.execute(httppost); // ERROR HAPPENS HERE 

responseXML = EntityUtils.toString(response.getEntity()); 
Log.d("Responce", responseXML);