I'm sending a HTTP GET request to an URL using NSURLConnection with the delegate. The request gets redirected with a HTTP 302 and the new request is performed and the data retrieved.
The problem is that I don't want the body of the redirected HTTP request but the content of the original redirect response.
I've implemented - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
which is called with the redirectRepsonse but connection:didReceiveData
is not called until the new redirected request returns.
I've found no solution so far except of using a CFNetwork based approach.
Update: I've created a sample project with the problem for you to play with: https://github.com/snod/302RedirectTest
Any ideas?
From the docs of -connection:willSendRequest:redirectResponse:
:
To receive the body of the redirect response itself, return nil to cancel the redirect. The connection continues to process, eventually sending your delegate a connectionDidFinishLoading or connection:didFailLoadingWithError: message, as appropriate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.