Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

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

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...