首先是请求的URL
NSString *url = @"your url";
接下来定义AFHTTPSessionManager,
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
设置相关的请求头,通过requestSerializer来实现,可以根据自己的需求(定义一个或者多个请求头),
[manager.requestSerializer setValue:@"value1" forHTTPHeaderField:@"key1"];
[manager.requestSerializer setValue:@"value2" forHTTPHeaderField:@"key2"];
......
实现带请求体的POST方法,
[manager POST:url
parameters:@{
@"key1":@"value1",
@"key2":@"value2"
......
}
progress:nil
success:^(NSURLSessionTask *task, id responseObject) {
NSLog("response:%@", responseObject);
}
}
failure:^(NSURLSessionTask *task, NSError *error) {
NSLog(@"error:%@", error);
}];
转载来自http://blog.csdn.net/lkj345/article/details/50626067
网友评论