简体   繁体   中英

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. 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.

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.

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.

You can use the HttpURLConnection to do this for you. See this link and scroll down to HTTP Authentication. 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. Same thing if you want to use HttpClient instead of HttpURLConnection. Either would work. If you want info on how to do it with HttpClient just google "Android HttpClient Basic Authentication"

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. You should only use Basic Authentication over a HTTPS connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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