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());