jar--android-async-http-1.4.5

Source: Internet
Author: User

    1. HTTP framework: Implementation of asynchronous access to the network;

    2. How to use:

(1) Create Httputil

Public class httputil {private static asynchttpclient client = new  asynchttpclient (); //  Instance Session object Static {client.settimeout (11000); //  set link timeout, if not set, The default is 10s}/** * url return string *  with no parameters @param  urlString url *  @param  res   Processing Handler */public static void get (string urlstring,  Asynchttpresponsehandler res) { client.get (urlstring, res);} /** * url with parameters return string *  @param  urlString url *  @param  params  Parameters in the URL  *  @param  res  processing handler */public static void get (string  Urlstring, requestparams params,asynchttpresponsehandler res) { // url with parameter Client.get ( Urlstring, params, res);} /** *  return json *  @param  urlString url  *  @param  res  Handling Handler */public static vOid get (string urlstring, jsonhttpresponsehandler res) { //  without parameters, Gets the JSON object or array client.get (urlstring, res);} /** *  with parameters, return json *  @param  urlString url *  @param  params  URL parameters  *  @param  res  processing handler */public static void get (string  Urlstring, requestparams params,jsonhttpresponsehandler res) { //  with parameters, Gets the JSON object or array client.get (urlstring, params, res);} /** *  with no parameters, returns byte data  *  @param  uString url *  @param  bHandler  Handling Handler */public static void get (String ustring, binaryhttpresponsehandler  bhandler) { //  Download data is used, it returns a byte data Client.get (Ustring, bhandler);} Public static asynchttpclient getclient ()  {return client;}}

(2) use in activity

URL gets string url = getstring (r.string.url);//Initialize network request parameters requestparams params =  New requestparams ();p arams.put (username, username);p arams.put (Password, password);//Network request, Processing return Data Httputil.get (Myconsts.url_login, params, new jsonhttpresponsehandler () {//Network request succeeded public  void onsuccess (Int statuscode, header[] headers,jsonobject response)  {// Successful acquisition of network data, where processing of data returned by the network}//server request failed Public void onfailure (int statuscode, header[] headers , string responsestring, throwable throwable)  {                                      //Visit network failed}//request end, regardless of success or failure to call the method public void  onfinish ()  {                                          //executes the method, whether successful or not});

Special Note: The OnFinish method is executed before the onsucess () and OnFailure () methods are executed;

jar--android-async-http-1.4.5

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.