如何为HTTPBody
对象和POST请求设置Json格式的AFHTTPSessionManager
?
现在我有:
[self.requestManager.requestSerializer setValue: @"application/json" forHTTPHeaderField:@"Content-Type"];
[self.requestManager POST:@"/api/register/"...
我收到错误:
请求失败:禁止(403)
我也试过了:
self.requestManager.requestSerializer = [AFJSONRequestSerializer serializer];
答案 0 :(得分:0)
==> afnetworking 3.0 Migration: how to POST with headers and HTTP Body
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
NSDictionary *parameters = @{@"test": @"this is a test"};
[manager POST:@"http://www...t" parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"%@",[responseObject description]);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",[error localizedDescription]);
}];