当请求:willRedirectToUrl:被实现时,ASIHTTPRequest停止下载

时间:2011-12-31 15:27:25

标签: objective-c ios cocoa-touch url asihttprequest

只要在委托中添加request:willRedirectToUrl:方法,请求就会停止从重定向的网址下载,如果我没有实现该方法,则会继续从新网址下载文件。它让我疯狂,为什么会这样?

1 个答案:

答案 0 :(得分:4)

如果你实现委托willRedirectToUrl,委托可以完全控制重定向会发生什么,所以它需要采取必要的行动 - 来自.h:

// Called on the delegate (if implemented) when the request receives a Location header and shouldRedirect is YES
// The delegate can then change the url if needed, and can restart the request by calling [request redirectToURL:], or simply cancel it

所以你只需要打电话:

// Can be called by delegates from inside their willRedirectSelector implementations to restart the request with a new url
- (void)redirectToURL:(NSURL *)newURL;

传递newURL。