如何从httpclient获取认证方案? [英] How to get authentication scheme from httpclient?

查看:64
本文介绍了如何从httpclient获取认证方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache httpclient连接到URL.每当我收到401错误时,我想知道服务器的身份验证方案吗? 像响应代码一样变得像response.getStatusLine().getStatusCode()一样,如何获得哪种身份验证方案?

Im using apache httpclient for connecting to a url.Whenever Im getting a 401 error I want to know server's authentication scheme? like Response code is getting like response.getStatusLine().getStatusCode() similarly how to get which auth scheme?

推荐答案

HttpClient教程是您的朋友.

HttpClient tutorial is your friend.

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

这篇关于如何从httpclient获取认证方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆