A simple-to-use HTTP request executor on iOS.
-
Copy the Core and Util folders into your project. You may need to replace the default log implementation in LogUtil.
-
Add a request parameter and make it inherit AHttpRequestParameter. Override
fillParameters:
method. Check TestGetParameter for example. -
Make your class where you want to process the response conform to ResponseDelegate, and implement
processResponse:
method. -
Create a response listener to process the response of the HTTP request.
There is a default implementation called HttpResponseJsonListener which will parse the response data into JSON format. You can create your own response listener by inheriting AHttpResponseListener.
-
Send your request.
To send a
GET
request, for example, all the code you need is:-(void)sendGetRequest { NSString *url = @"your url here"; HttpResponseJsonListener *listener = [HttpResponseJsonListener instanceWithRequestId:1001 observer:self]; // 1001 is used to identify a request from another [RequestExecutor executeAsyncGet:url parameter:[[TestGetParameter alloc] init] responseListener:listener]; } -(void)processResponse:(HttpRequestResult *)result { if (result.requestId == 1001) { NSLog(@"requestId=%ld, %@", (long)result.requestId, result.data); } else if (result.requestId == 1002) { NSLog(@"requestId=%ld, %@", (long)result.requestId, result.data); } else { } }