i have a connection use NSURLConnection, i want to draw a progress for this connection but when i try to print current received data and total data length, something went wrong ,response.expectedContentLength allway return -1, why and what happen with my connection, how can i fix it
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
receivedDataBytes += [data length];
NSLog(@"data: %f",receivedDataBytes);
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.HTTPStatusCode = [(NSHTTPURLResponse *)response statusCode];
totalFileSize = response.expectedContentLength;
NSLog(@"total: %lf",totalFileSize);
}
output:
total: -1.000000
data: 1256.000000
total: -1.000000
data: 1034.000000
total: -1.000000
data: 1127.000000