iOS 从 URL 下载文件,该 URL 将重定向到该文件 [英] iOS download file from a URL that will redirect to the file
问题描述
我已经尝试了 2 天,但无法解决这个问题.
I've been trying for 2 days and cant figure this out.
基本上我有一个 URL,我尝试使用 ASIHTTPRequest 下载与其关联的文件,但我拥有的 URL 不是文件本身的链接,但该 URL 将重定向到实际文件的链接.我尝试将该链接提供给 ASIHTTPRequest 以供下载,但没有.所以我想我必须以某种方式获取重定向的 url 并将其提供给 ASIHTTPRequest 以下载文件.
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.
我该怎么做?
感谢大家阅读:)
推荐答案
你实现了 ASIHTTPRequest 的这个委托方法- (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL 方法被调用,但在请求没有像我假设的那样重定向之后.您必须自己重定向请求:
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];
}
这篇关于iOS 从 URL 下载文件,该 URL 将重定向到该文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!