I am downloading file (with apache tomcat 6.0.32). When I make disconnect (shutdown tomcat) some times ASHITTPRequest generate error, but sometimes (most of times exactly...ALL TIME EXACTLY! Only if there is no connection at the beginning occurs error) it ends work like all correct.
So there is the question: why this happened and how can I watch if the connection lost properly.
Thanks a lot!
UPDATE:
Try to send request through TCPMon and then stop it (TCPMon) and get the same: ASIHTTPRequest think that the downloading correctly done.
UPDATE:
responseHeaders:
"Content-Disposition" = attachment;
"Content-Length" = 2277888;
"Content-Type" = "application/octet-stream";
Date = "Thu, 28 Apr 2011 12:35:32 GMT";
Server = "Apache-Coyote/1.1";
"Set-Cookie" = "JSESSIONID=98CAE6C0C4275B528D5E0F8651546AFE; Path=/ISED";
responseStatusMessage:
HTTP/1.1 200 OK
UPDATE:
If disconnect computer by hand (disconnect the cable) and get this:
Sometime ASIHTTPRequest waits till timeout, and next request get connecting error.
Sometime error occurs just in time I disconnect.
Sometime error does not occurs just in time I disconnect: download progress missing and (if make connection again) it file starts download from the beginning.
And if close port ASIHTTPRequest thinks that is successful download done.
I can't understand this logic...
SOLUTION:
I solve the problem by comparing Content-Length in header and total bytes read:
NSString *contentLength = [[self.request responseHeaders] valueForKey:@"Content-Length"];
NSString *downloadedBytesCount = [NSString stringWithFormat:@"%llu",[self.request totalBytesRead]];
if ([contentLength isEqualToString:downloadedBytesCount] == NO) {
// error maintain
}
So I can check if I got all data and if not: maintain error. In other cases (like manually disconnect) ASIHTTPRequest work appropriate way and generates errors by self.