0
我使用Apache httpclient連接到一個url.Whenever我得到401錯誤我想知道服務器的身份驗證方案? 像響應代碼越來越像response.getStatusLine()。getStatusCode()類似如何得到哪個auth方案?如何從httpclient獲取認證方案?
我使用Apache httpclient連接到一個url.Whenever我得到401錯誤我想知道服務器的身份驗證方案? 像響應代碼越來越像response.getStatusLine()。getStatusCode()類似如何得到哪個auth方案?如何從httpclient獲取認證方案?
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());