【问题标题】:ASIHTTPRequest stops downloading when request:willRedirectToUrl: is implemented实现 request:willRedirectToUrl: 时 ASIHTTPRequest 停止下载
【发布时间】:2011-12-31 15:27:25
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    如果您实现委托 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;
    

    传递新的URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多