2016-02-08 69 views
0

我想通過從Java應用程序傳遞證書登錄到網頁? 我使用下面的代碼,但收到的一些錯誤:我想通過從java應用程序傳遞證書登錄到網頁

HttpClient client = new HttpClient(); 
client.getParams().setParameter("User Name", "user"); 
client.getParams().setParameter("Password", "password"); 
GetMethod request = new GetMethod("url"); 

錯誤: 信息:可用於NTLM @ 192.168.224.142無憑據:7048

我也曾嘗試下面的代碼:

HttpClient client = new HttpClient(); 
     client.getState().setCredentials(AuthScope.ANY, new NTCredentials("user", "password", "ip:port", "http")); 
     GetMethod request = new GetMethod("url"); 

錯誤:信息:驗證失敗使用NTLM

建議通過從Java應用程序傳遞憑據來登錄到網頁?

+0

Ntlm示例https://gist.github.com/virtix/1340440 –

回答

0

您正在將您的用戶憑證作爲GET請求參數傳遞。該網站預計基於NTLM的認證(用戶名和密碼不會被髮送到服務器)。

使用org.apache.http.auth.NTCredentials來存儲您的用戶名和密碼。

NTCredentials userCredentials = new NTCredentials(userName, password, 
            System.getProperty("COMPUTERNAME"), domain); 
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); 
credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, 
             AuthScope.ANY_PORT), userCredentials); 
HttpClientContext httpClientContext = HttpClientContext.create(); 
httpClientContext.setCredentialsProvider(credentialsProvider); 
HttpClient httpClient = HttpClientBuilder.create(). 
         setDefaultCredentialsProvider(credentialsProvider).build(); 

隨時根據您的需要修改AuthScope

+0

我應該在「域」中使用什麼 –

+0

CredentialsProvider credentialsProvider = new BasicCredentialsProvider();錯誤:BasicCredentialsProvider無法解析爲類型 –

+0

我不認爲該庫是NTLM所必需的 –