如何处理“太多的HTTP重定向”?错误

问题描述:

当我将网站加载到可可应用程序的webview中时,就会出现此问题。
我的问题描述:

This issue comes when i load website into webview of my cocoa application. my issue description:


Error Domain = NSURLErrorDomain代码= -1007 HTTP重定向过多
UserInfo = 0x18d17d56 {NSErrorFailingURLStringKey = URLHERE,
NSErrorFailingURLKey = URLHERE,NSLocalizedDescription =太多HTTP
重定向}

Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects" UserInfo=0x18d17d56{NSErrorFailingURLStringKey=URLHERE, NSErrorFailingURLKey=URLHERE,NSLocalizedDescription=too many HTTP redirects}

为什么这样做错误来了

如何处理

why this error comes
how to handle it

我通过以下链接访问了但对我没有帮助

i go though following links but does't help me

HTTP重定向过多

HTTP重定向过多;在使用Alamofire上传多部分表单数据时

太多的HTTP重定向,Google Drive,iOS SDK 等等。

更新:

- (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource {
    if(redirectResponse)
    {
        if([redirectResponse.URL.absoluteString isEqualToString:self.webviewLoadingURL.absoluteString])
        {
            NSLog(@"both redirect and load url is same");
        }
    }
    return request;
}

我在重定向和加载到Webview中使用相同的URL。

I getting same url for redirect and load in webview.

这几乎总是由服务器配置错误引起的,该错误导致网页重定向到自身(可能是通过另一个中间URL)。除非问题是由您的客户端代码请求无效/不正确的URL引起的,否则您可能无法在客户端上解决此问题。

This is almost invariably caused by a server configuration error that causes the web page to redirect to itself (possibly by way of another intermediate URL). There's probably nothing you can do to fix this on the client side unless the problem is caused by your client code requesting an invalid/incorrect URL.

如果您询问如何为了向用户呈现错误,我想你应该像对待404一样对待它。该URL不太可能很快就开始工作。

If you're asking how to present the error to the user, I would say that you should treat it in the same way that you'd treat a 404. That URL isn't likely to start working any time soon.