How to display HTTP 401 basic authentication dialog

点点圈 提交于 2019-12-19 11:49:24

问题


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:

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.


回答1:


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"

The client can then retry the request while sending a base64 encoded header in the format username:password.

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

See also: http://en.wikipedia.org/wiki/Basic_access_authentication



来源:https://stackoverflow.com/questions/15177325/how-to-display-http-401-basic-authentication-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!