Asynchttpclient client =Newasynchttpclient (); Requestparamsparams=Newrequestparams ();params. put ("Key","value");params. put (" More","Data"); client.Get("http://www.google.com",params,NewAsynchttpresponsehandler () {@Override Public voidOnsuccess (intStatusCode, header[] headers,byte[] response) {System. out. println (response); } @Override Public voidOnFailure (intStatusCode, header[] headers,byte[] responsebody, throwable error) {LOG.D ("ERROR", error); }}); The above example is the case where the returned response is directly the original word stream, if you need to treat the returned result as a string, you only need to implement a texthttpresponsehandler anonymously. It inherits from Asynchttpresponse and converts the native byte stream into a string object based on the specified encoding, asynchttpclient client=Newasynchttpclient (); Requestparamsparams=Newrequestparams ();params. put ("Key","value");params. put (" More","Data"); client.Get("http://www.google.com",params,NewTexthttpresponsehandler () {@Override Public voidOnsuccess (intStatusCode, header[] headers, String response) {System. out. println (response); } @Override Public voidOnFailure (intStatusCode, header[] headers, String responsebody, throwable error) {LOG.D ("ERROR", error); } });
Android-async-http asynchttpclient Introduction