objective-c - ASIHTTPRequest 在请求 :willRedirectToUrl: is implemented 时停止下载

标签 objective-c ios cocoa-touch url asihttprequest

只要我添加 request:willRedirectToUrl:委托(delegate)中的方法请求停止从重定向的 url 下载,如果我不实现它继续从新 url 下载文件的方法。快把我逼疯了,为什么会这样?

最佳答案

如果您实现委托(delegate) willRedirectToUrl,则委托(delegate)可以完全控制重定向将发生的情况,因此它需要采取必要的措施 - 从 .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;

传递新的URL。

关于objective-c - ASIHTTPRequest 在请求 :willRedirectToUrl: is implemented 时停止下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8688919/

相关文章:

ios - 强 block 捕获 'self'

ios - 从 CoreData 获取到 TableView

ios - Swift 项目中的 SignalR-ObjC

ios - collectionView在swift中加载xib而不是数组中的内容

iPhone 一个 Controller ,多个 View

iphone - 从 Facebook ID 查找用户名的最佳方法

objective-c - 将携带字典对象的 NSdata 与 String 进行比较

ios - Objective-C:NSMutableArray 的未转换元素返回意外类型

iphone - 如何获取动态创建的UITextView iphone的高度

objective-c - 如何在 Objective-C 中将文本转换为驼峰式大小写?