401 Unauthorized 客户试图未经授权访问受密码保护的页面

401 Unauthorized 客户试图未经授权访问受密码保护的页面。应答中会包含一个WWW-Authenticate头,浏览器据此显示用户名字/密码对话框,然后在填写合适的Authorization头后再次发出请求。


response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate","Basic realm=\"SNS Secure Area\"");



获取用户名密码为:
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
String authorization = request.getHeader("authorization");
System.out.println("authorization:"+authorization);

String userName = null;
String password = null;

if (authorization != null && authorization.length()>0) {
if (authorization.startsWith("Basic")){
authorization = authorization.substring(authorization.indexOf(' ')+1);
byte[] bytes = decoder.decodeBuffer(authorization);
authorization = new String(bytes);
userName = authorization.substring(0,authorization.indexOf(':'));
password = authorization.substring(authorization.indexOf(':')+1);
System.out.println("userName:"+userName);
System.out.println("password:"+password);
}else if (authorization.startsWith("Digest")){
userName = authorization.substring(authorization.indexOf("username="));
userName = userName.substring("username=\"".length());
userName = userName.substring(0,userName.indexOf('"'));
password = authorization.substring(authorization.indexOf("response="));
password = password.substring("response=\"".length());
password = password.substring(0,password.indexOf('"'));
}

System.out.println("userName:"+userName+"\npassword:"+password);

}



05:19:08,515 INFO [STDOUT] ====================x-requested-with:XMLHttpRequest
05:19:11,421 INFO [STDOUT] ====================accept-language:zh-cn
05:19:13,078 INFO [STDOUT] ====================referer:http://localhost:8080/ams/lephone/2.5/appreview.do?lcaid=4104
05:19:14,218 INFO [STDOUT] ====================accept:*/*
05:19:18,203 INFO [STDOUT] ====================content-type:application/x-www-form-urlencoded
05:19:47,343 INFO [STDOUT] ====================accept-encoding:gzip, deflate
05:19:20,734 INFO [STDOUT] ====================user-agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2)
05:19:48,656 INFO [STDOUT] ====================host:localhost:8080
05:19:22,750 INFO [STDOUT] ====================content-length:48
05:19:49,921 INFO [STDOUT] ====================connection:Keep-Alive
05:19:50,578 INFO [STDOUT] ====================cache-control:no-cache
05:19:25,421 INFO [STDOUT] ====================cookie:JSESSIONID=D744F0509E590D7F3EA343326882BDEA; clientid=null661a1d2a5e97432c80ebf82fb23da2bb; lpsust=""
05:19:26,343 INFO [STDOUT] ====================authorization:Basic b29vb29vb29vbzpkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRk
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值