我正在编写一个简单的客户端服务器应用程序,并且必须将AFNetworking更新到2.0版。我的问题是即使我从我的服务器返回403,操作管理器也总是陷入成功阻止。
这是我从Django服务器返回的内容:
return HttpResponseForbidden(content_type="application/json")
我像这样扩展了OperationManager:
User : AFHTTPRequestOperationManager
这就是我的初始化方式:
-(id)initWithBaseURL:(NSURL *)url
{
self = [super initWithBaseURL:url];
if (self)
{
[self setResponseSerializer:[AFJSONResponseSerializer serializer]];
[self setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[self.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
}
return self;
}
我的获取请求如下:
[self GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Get request success.");
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Get request failed.");
[[NSNotificationCenter defaultCenter] postNotificationName: @"connectionError" object: error];
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];
我意识到AFURLConnectionOperation的responseData始终为null,因为永远不会调用AFURLConnectionOperation的函数:
- (void)connection:(NSURLConnection __unused *)connection
didReceiveData:(NSData *)data
谢谢。我在等你的帮忙!!