<span style="font-size:18px;">// Request: My API (1) (http://m.app.shouyou.com/indexImage/list.json)
NSURL* URL = [NSURL URLWithString:@"http://m.app.shouyou.com/indexImage/list.json"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";
request.timeoutInterval = 30;
// Request Operation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
// Body
NSDictionary *parameters =@{@"input": @{@"appId":@9,@"deviceType":@2}};
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:nil];
// Progress & Completion blocks
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: Status Code %ld", (long)operation.response.statusCode);
NSLog(@"%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error.localizedDescription);
}];
// Connection
[operation start];</span>
使用AFNetWorking请求的一段通用代码,直接替换网址参数即可
最新推荐文章于 2018-11-21 15:50:29 发布