Created
August 28, 2014 09:03
-
-
Save peerax/7be39327f8e71ff65773 to your computer and use it in GitHub Desktop.
NSUrlsession use POST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; | |
NSMutableURLRequest *request = [NSMutableURLRequest | |
requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@/getAllUser",[GlobalVar serverIp],[GlobalVar serverPort]]]]; | |
NSDictionary *requestData = [[NSDictionary alloc] initWithObjectsAndKeys: | |
[defu objectForKey:@"ComId"], @"id", | |
nil]; | |
NSError *error; | |
NSData *postData = [NSJSONSerialization dataWithJSONObject:requestData options:0 error:&error]; | |
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; | |
[request setHTTPMethod:@"POST"]; | |
[request setHTTPBody:postData]; | |
//NSLog(@"%@",requestData); | |
NSURLSession *session = [NSURLSession sharedSession]; | |
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | |
if (!error) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; | |
NSLog(@"%@",dic); | |
RetArray = [[NSArray alloc] init]; | |
RetArray = [dic objectForKey:@"res"]; | |
[defu setObject:RetArray forKey:@"userList"]; | |
[defu synchronize]; | |
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; | |
[[NSNotificationCenter defaultCenter]postNotificationName:@"gotoloadTable" object:self]; | |
}); | |
} | |
}]; | |
[dataTask resume]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment