简体   繁体   English

Android应用程序开发,Web服务器和htpasswd

[英]Android App Development, Web Server, and htpasswd

I am developing an Android app that ties into a web app thats also being built in parallel the problem is, the services web side are being built behind htpasswd auth. 我正在开发一个Android应用程序,该应用程序与并行构建的Web应用程序相关,问题是,服务Web端正在htpasswd auth后面构建。 Which I believe is going to hinder my ability to make an android app that will work with the RESTful services we are building into the web side for the mobile side. 我认为这将阻碍我制作一个Android应用程序的能力,该应用程序将与我们正在构建到移动端的Web端的RESTful服务一起工作。

So my question there is and I am a complete newb with Android development as is, is there a means where I can keep the htpasswd auth on the development server where everything else is being set up while bypassing the auth, or provide the credentials some how for it. 所以我的问题是,我是Android开发的完整新手,有没有办法让我可以在开发服务器上保留htpasswd auth,其中包含其他所有设置,同时绕过auth,或提供一些凭据如何为了它。

A website that has a portion of itself locked down to a username and password like that is using what is known as Basic Authentication. 将自身的一部分锁定为用户名和密码的网站正在使用所谓的基本身份验证。 You just need to put the Base64 encoded username:password into the authentication field of the HTTP header. 您只需将Base64编码的用户名:密码放入HTTP标头的身份验证字段中即可。

You can use the HttpURLConnection to do this for you. 您可以使用HttpURLConnection为您执行此操作。 See this link and scroll down to HTTP Authentication. 请参阅此链接并向下滚动到HTTP身份验证。 Basically what you do is when you make the HttpURLConnection to contact your REST service you provide it with the username and password and it will handle the rest for you. 基本上你所做的就是当你让HttpURLConnection联系你的REST服务时,你提供了用户名和密码,它将为你处理剩下的事情。 Same thing if you want to use HttpClient instead of HttpURLConnection. 如果你想使用HttpClient而不是HttpURLConnection,也是一样的。 Either would work. 要么工作。 If you want info on how to do it with HttpClient just google "Android HttpClient Basic Authentication" 如果您想了解如何使用HttpClient进行操作只需谷歌“Android HttpClient基本身份验证”

One thing to keep in mind. 要记住一件事。 when you use basic authentication the username and password are sent in the web request and can be seen by third parties. 当您使用基本身份验证时,用户名和密码将在Web请求中发送,并可由第三方查看。 You should only use Basic Authentication over a HTTPS connection. 您应该只通过HTTPS连接使用基本身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM