0
当我在可可中运行我的NSURLRequest时,出现303 HTTP错误,这是一个重定向。我如何才能将正确的URL重定向到?它是在错误变量还是其他地方?如何处理NSURLRequest HTTP错误303?
当我在可可中运行我的NSURLRequest时,出现303 HTTP错误,这是一个重定向。我如何才能将正确的URL重定向到?它是在错误变量还是其他地方?如何处理NSURLRequest HTTP错误303?
你可能想看看重定向的自动处理与NSURLConnection的:
Handling Redirects and other Request Changes
如果你想手动处理它,重定向URL是响应的“位置”标头。您可以通过connection:didReceiveResponse
委托方法获得该方法。
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
// ... if the response status is 303 ...
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSString* location = [[httpResponse allHeaderFields] valueForKey:@"Location"];
// do whatever with the redirect url
}
}
有时我们会在头部位置相对URL。你能建议如何处理这些?例如,我正在打开一个页面m.espn.go.com,并在响应位置标题字段I get Location:/ index。如何处理这个。 – iProgrammer 2014-05-09 11:18:22