iOS processing network requests, with more than the third-party tool class afnetworking, because the native is more troublesome.
If you log in to send account and password with the background comparison, the process is as follows, back in the background is JSON, such as
{"Login": {"id": "0001", "status": "OK", "errormsg": ""}}
Here is an example of when to use.
1 #import "AFNetWorking.h"2 3NSString Urllogin =@"www.xxx.com";4 //Create request Manager5Afhttprequestoperationmanager *requestmanager =[[Afhttprequestoperationmanager alloc] init];6 //affirm that the requested data is of type text/html7RequestManager.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@"text/html", nil];8RequestManager.requestSerializer.HTTPShouldHandleCookies =YES;9 [Requestmanager get:urlloginTen Parameters:nil Onesuccess:^ (Afhttprequestoperation *operation,IDresponseobject) { ANsdictionary *dict = responseobject[@"Login"]; -NSString *str = [Dict objectforkey:@"Status"]; -NSString *errormsg = [Dict objectforkey:@"errormsg"]; the //If you succeed, jump to the next page - if(str && [str isequaltostring:@"OK"]) { -Mstabbarviewcontroller *tabbar =[[Mstabbarviewcontroller alloc] init]; - [self Presentviewcontroller:tabbar animated:yes completion:nil]; +}Else { - //The comparison is not successful, pop-up hints +Self.alertview = [[Uialertview alloc]initwithtitle:@""Message:errormsgDelegate: Self Cancelbuttontitle:@"cancle"Otherbuttontitles:@"OK", nil]; A [Self.alertview show]; at } - -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"Server Error"); -}];
Of course, the premise is to introduce afnetworking files.
Easy use of iOS network processing--afnetworking