Using the ASIHTTPRequest Third library, you need to configure
Two
Upload data function using asifromdatarequest (can upload binary and string to server)
Down here, kind.
// build a project, import a third-party library, and AppDelegate.h #import <UIKit/UIKit.h>#import"ASIFormDataRequest.h"@ Interface Appdelegate:uiresponder <UIApplicationDelegate,ASIHTTPRequestDelegate>{ / / Declare the member variable of the data request asiformdatarequest **window; @end
//code written in APPDELEGATE.M.//loading data via POST requestNsurl *url=[nsurl urlwithstring:@"http://10.0.8.8/sns/my/login.php"];//instantiate as Object_request=[[Asiformdatarequest Alloc]initwithurl:url];//Set Request Mode[_request Setrequestmethod:@"Post"];//Adding Parameters[_request Addpostvalue:@"AA_ZX"Forkey:@"username"]; [_request Addpostvalue:@"FFFF"Forkey:@"Password"];//Set proxy callbacks_request.Delegate=Self ;//Request Data[_request startasynchronous];//asynchronous requests, multithreading
#param-Mark ASIHTTPRequest-(void) requestfinished: (ASIHTTPRequest **dict=[ Nsjsonserialization JSONObjectWithData:request.responseData options:nsjsonreadingmutablecontainers Error:nil ]; NSLog (@ "%@", Dict);} -(void) requestfailed: (ASIHTTPRequest *) request{ NSLog (@ " request failed " );}
Third, load the network data, asihttprequest (all formats of data can be loaded)
-(void) Startloadwebdata: (NSString *) strurl{//instantiating a ASIHTTPRequest objectNsurl *url=[Nsurl urlwithstring:strurl];_request=[[ASIHTTPRequest alloc]initwithurl:url];_requent.Delegate=Self ;//Start Loading Data[_requenst startasynchronous];}#pragma-mark asihttprequestdelegate//call this method when the request succeeds-(void) requestfinished: (ASIHTTPRequest *) Request{nsdictionary*dict=[Nsjsonserialization JSONObjectWithData:request.responseDataoptions:NSJSONReadingMutableContainers Error:nil ];//Agent receives data[Self.DelegateRecivedata:[dict Objectforkey:@"Application"];}//call this method when requesting network data fails-(void) requestfailed: (ASIHTTPRequest *) Request{nslog (@"failed");}
ASIHTTPRequest load network data and upload data functions