Skip to content

Instantly share code, notes, and snippets.

@hashmaparraylist
Created July 2, 2015 17:00
Show Gist options
  • Save hashmaparraylist/139d54fe0fb57211939e to your computer and use it in GitHub Desktop.
Save hashmaparraylist/139d54fe0fb57211939e to your computer and use it in GitHub Desktop.
AFURLSessionManager发送DataTask
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];
@hashmaparraylist
Copy link
Author

注释1

@hashmaparraylist
Copy link
Author

注释2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment