views:

27

answers:

1

Hi,

I am sending a request with POST data to a web server. The web server returns with JSON response in case of an error or the file data itself if there are no errors.

I would like to track the progress of the file data response. My code is based on the the sample code from ASIHttpRequest Tutorial

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setPostValue:someValue forKey:@"someKey"];
[request setPostValue:someOtherValue forKey:@"someOtherKey"];
[request setShowAccurateProgress:YES];
[request setDownloadProgressDelegate:aProgressView];

request.delegate = self;
[request startSynchronous];

Nothing happens until the complete response is there, in which case the progress bar fills up completely.

I experimented with both synchronous and asynchronous requests.

I guess the download progress delegate does not work, because I am not downloading a file per se, but just receiving the HTTP response to the request, right? What would be the correct approach to monitor the progress in this case?

Thanks in advance...

+1  A: 

Are you running this code in the main thread?

If so the reason the progress doesn't update is that using a synchronous request will be blocking the main thread, preventing UI updates from happening.

The best fix for that is to use an asynchronous request - you mentioned you've tried that, what happened?

JosephH
that was my first idea as well, but both async and sync requests result in similar behavior. even during an async request the updateProgress method never gets called until the whole response has been received.
Engin Kurutepe
Another possibility would be if the server is not returning a Content-Length: header - then ASIHTTPRequest has no way to know what the total size of the download is, so can't report percentage complete. There's also a known bug in apache when it can report the wrong size for compressed responses, so ASIHTTPRequest disables progress reporting in that case. If you add the full headers of the HTTP response from the response into your question that might make it possible to diagnose.
JosephH
Thanks a lot Joseph. Content-Length was not being set indeed. The server guys fixed it and it's working as expected now!
Engin Kurutepe