Created
July 2, 2015 17:00
-
-
Save hashmaparraylist/139d54fe0fb57211939e to your computer and use it in GitHub Desktop.
AFURLSessionManager发送DataTask
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
| NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
| AFURLSessionManager *sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; | |
| NSURL *url = [NSURL URLWithString:apiURL]; | |
| NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | |
| [request setHTTPMethod:method]; | |
| [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | |
| if (isNeedToken) { | |
| [request setValue:[NSString stringWithFormat:@"token %@", self.token] forHTTPHeaderField:@"Authorization"]; | |
| } | |
| NSURLSessionDataTask *dataTask = [sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { | |
| if (error) { | |
| NSLog(@"Error: %@", error); | |
| } else { | |
| NSLog(@"%@ %@", response, responseObject); | |
| } | |
| }]; | |
| [dataTask resume]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
注释1