Question

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...

Was it helpful?

Solution

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?

Tip:

Print http response and check if you have Content-Length. If not, or it's 0 that's the problem.

NSLog(@"Response headers %@",[request responseHeaders]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top