Android uses basic auth for login verification

Source: Internet
Author: User
Tags oauth
 Public String get (string neturl, string USR, string psw) {URL url = new URL (neturl ); usernamepasswordcredentials UPC = new usernamepasswordcredentials (USR, psw); // the username and password are used to create a data authscope as = new authscope (null,-1 ); basiccredentialsprovider BCP = new basiccredentialsprovider (); // I copied the following section =. = BCP. setcredentials (AS, UPC); defaulthttpclient dHC = new defaulthttpclient (); dHC. setcredentialsprovider (BCP); // set an authentication part for the client/* ------------------------- split line **/httpget Hg = new httpget (neturl); httpresponse hR = NULL; hR = dhc.exe cute (Hg); string line = NULL; stringbuilder builder = new stringbuilder (); bufferedreader reader = NULL; reader = new bufferedreader (New inputstrea Mreader (HR. getentity (). getcontent (); // get data while (line = reader. Readline ())! = NULL) builder. append (line); string strcontent = builder. tostring (); reader. close (); log. D ("info", strcontent); Return strcontent ;}

If you want to create a client, login is essential. Android has a built-in oauth login component. You can easily add this content to the get and post headers to complete the verification function.

Next, go to the topic: I want to create a client for the Forum. The Forum uses the oauth verification system. This requires a usernamepasswordcredentials, authscope, and basiccredentialsprovider class. For details, refer to it.CodeNow!

The above part of the split line is the main part of the oauth verification. I may not be clear about the reason, but this code can be used directly after it is taken. You can try it.

Reprinted please indicate from: http://blog.csdn.net/icyfox_bupt/article/details/8843145

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.