如何显示HTTP 401基本身份验证对话框 [英] How to display HTTP 401 basic authentication dialog
问题描述
我是网络开发的新手。我有Android应用程序使用HTTPServer托管一些网页。我正在使用Netty来解码/编码请求/响应。现在,我想在有人导航到我的网页时显示基本身份验证对话框。这样的事情:
I am new to web development. I have Android application that hosts some web pages using HTTPServer. I am using Netty to decode/encode request/responses. Now, I want to display basic authentication dialog when someone navigates to the my webpage. Something like this:
可以我得到了一些指示?这是HTTP内置的功能,任何RFC?我需要编写一些java脚本吗?任何帮助都会很棒。
Can I get some pointers ? Is it something HTTP built in functionality, any RFC ? Do I need to write some java script ? Any help would be great.
推荐答案
当客户端请求您要求身份验证的资源时,您只需要发送相应的标头for。
You just need to send the appropriate headers when a client requests a resource you want to require authentication for.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Restricted Area"
然后客户端可以在以用户名:密码格式发送base64编码标头时重试请求
。
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
另请参阅: http:// en .wikipedia.org / wiki / Basic_access_authentication
这篇关于如何显示HTTP 401基本身份验证对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!