2012-03-13 9 views
0

私はurlに接続するためにApache HTTPClientを使用しています。私は401エラーを取得するたびにサーバーの認証方式を知りたいのですか?応答コードはresponse.getStatusLine()。getStatusCode()と同様にどのように認証スキームを取得するのですか?httpclientから認証方式を取得するには?

答えて

0

HttpClientチュートリアルはあなたの友人です。


HttpClient httpclient = new DefaultHttpClient(); 
HttpContext localContext = new BasicHttpContext(); 
HttpGet httpget = new HttpGet("http://localhost:8080/"); 
HttpResponse response = httpclient.execute(httpget, localContext); 

AuthState targetAuthState = (AuthState) localContext.getAttribute(ClientContext.TARGET_AUTH_STATE); 
System.out.println("Target auth scope: " + targetAuthState.getAuthScope()); 
System.out.println("Target auth scheme: " + targetAuthState.getAuthScheme()); 

関連する問題