【发布时间】:2015-03-18 19:58:49
【问题描述】:
所以,我正在从使用 ASI 库切换到 AFNetworking,并且遇到了重定向请求问题。这是我正在使用的代码:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:originalRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
debugLog(@"SM Success, Redirect URL: %@",[[[operation response] URL] absoluteString]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
debugLog(@"SM Fail: %@", error);
}];
[operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
if (redirectResponse) {
debugLog(@"REDIRECT URL: @%", [request URL]);
NSMutableURLRequest *r = [originalRequest mutableCopy];
[r setURL: [request URL]];
return r;
} else {
debugLog(@"Redirecting to : %@", [request URL]);
return request;
}
}];
我想做的是将重定向请求从 GET 更改为 POST。在 ASI 中,我明确禁止了所有重定向,一旦收到 302 状态,我将创建一个新请求并将其作为 POST 发送。我应该对 AFNetworking 做同样的事情吗?
【问题讨论】:
标签: ios xcode redirect afnetworking afnetworking-2