I'm uisng ASIHTTPRequest for HTTP requests and to save result into separate file. As the file is expected to be large, it should also be able to resume.
request.allowResumeForFileDownloads = YES;
request.downloadDestinationPath = destFile;
request.temporaryFileDownloadPath = tmpFile;
I use the following selectors:
request.didFinishSelector = @selector(didFinishRequest:);
request.didFailSelector = @selector(didFailRequest:);
request.didReceiveResponseHeadersSelector = @selector(didReceiveResponse:);
Now I'm testing different cases with loosing connection, different proxies, etc and found a problem, that if a response is received with code other like 503 or something, then ASIHTTPRequest still saves result into temp file, which is wrong, because the data is some random HTML page with error (if there was partial downloaded file, then this HTML is appended to it which makes my data corrupted).
So what I'm trying to do is to check response code and if it is not 2XX, then cancel request without saving anything.
This doesn't help:
- (void)didReceiveResponse:(ASIHTTPRequest*)request {
if (request.responseStatusCode < 200 || request.responseStatusCode >= 300) {
[request clearDelegatesAndCancel];
Any ideas?