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