我正在使用AFNetworking处理从我的移动应用程序到我的rails服务器的重置密码请求。
api正在回归: head:ok(结果为200)
但是,当我发出getPath
请求时,这会导致AFNetworking运行失败阻止。
我可以做两件事来成功阻止运行:
head :no_content
(结果为204)当状态代码为200且Accept标头为application/json
时,AFNetworking似乎期望至少有一个空数组。
我没有对api的完全控制,所以有可能让200没有内容仍然触发我的成功阻止,或者是204应该用于这个确切的情况,它成功但没有任何意义从服务器返回?
谢谢!
答案 0 :(得分:2)
您可以使用AFHTTPRequestOperation
并自行处理响应代码,而不是使用AFNetworking的成功和完成功能块。例如:
// Setup HTTP client
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://website.com"]];
// Create the request
NSURLRequest *request = [client requestWithMethod:@"GET" path:@"authenticate" parameters:params];
// Create an HTTP operation with your request
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
// Setup the completion block
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
switch (operation.response.statusCode) {
case 200:
// Do stuff
break;
default:
break;
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
switch (operation.response.statusCode) {
case 400:
// Do stuff
break;
default:
break;
}
}];
// Begin your request
[operation start];