2
我需要一些幫助使DIGEST身份驗證正常工作。我正在使用apache 4.1庫。當我嘗試登錄我得到。Java摘要身份驗證POST XML
線程「main」 javax.net.ssl.SSLPeerUnverifiedException例外:同行不認證
我試圖登錄到Asterisk的Switchvox的開發擴展API,您只需發送一個XML後,它給你返回信息。我當然有正確的用戶名/密碼,我得到這個PERL腳本的工作,但我不能在JAVA中獲得它。
這裏是我的代碼
public class Main {
public static void main(String[] args) throws Exception {
HttpHost targetHost = new HttpHost("192.168.143.253", 443, "https");
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("192.168.143.253", targetHost.getPort()),
new UsernamePasswordCredentials("username", "mypassword"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate DIGEST scheme object, initialize it and add it to the local auth cache
DigestScheme digestAuth = new DigestScheme();
authCache.put(targetHost, digestAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
HttpGet httpget = new HttpGet("https://192.168.143.253/xml/");
System.out.println("executing request: " + httpget.getRequestLine());
System.out.println("to target: " + targetHost);
for (int i = 0; i < 3; i++) {
HttpResponse response = httpclient.execute(targetHost, httpget, localcontext);
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();
}
}
}
您沒有使用'DigestScheme digestAuth =新DigestScheme();'在你的答案。這是如何與Digest安全性(我知道代碼工作,我想知道它的安全性) – 2014-02-21 13:44:11