iOS download file from a URL that will redirect to the file

不想你离开。 提交于 2019-12-12 02:55:57

问题


I've been trying for 2 days and cant figure this out.

Basically I have a URL and I try to download the file that associate with it using ASIHTTPRequest, but the URL I have is not the link of the file itself, but that URL will redirect to the link of the actual file. I try to give that link to ASIHTTPRequest for download, but it didn't. SO I think I have to somehow get the redirected url and feed that to ASIHTTPRequest to download the file.

How can I do this?

Thanks all for reading :)


回答1:


You implement this delegate method of ASIHTTPRequest - (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL the Method is called, but after the request isn't redirected as I asumed. You have to redirect the request by yourself:

  - (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL 
  {
   // modify request here, e.g. set request headers again...
   [request redirectToURL:newURL];
  }


来源:https://stackoverflow.com/questions/10782388/ios-download-file-from-a-url-that-will-redirect-to-the-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!