Don't use [request start] to start requests - use [request startAsynchronous] instead.
It looks like this is a timeout. How large is the data you are posting? Is it larger than the amount of data ASIHTTPRequest reported it had sent (33308+ 229376 bytes) ? Is this over wifi, or wwan?
Best
Ben
Thanks for the tip on [request startAsynchronous]. Unfortunately, I'm
still experiencing the same issue.
It does eventually repeat the "0 bytes of bandwidth in last
measurement period" until ASI hits it's request timeout.
The data I'm posting is pretty insignificant, generally around 800KB.
This is over wifi to an Amazon's EC2 instance (actually a Rails app on
Heroku). I've been able to post via curl on the command line w/o any
timeout issues. So it looks like the problem is contained to my app /
ASI.
Best,
-Matt
> --
> You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
> To post to this group, send email to asihttp...@googlegroups.com.
> To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.
>
>
So I've spent some more time digging into this and it's very strange.
Here's the code I'm using now to post a file:
ASIFormDataRequest *request = [ASIFormDataRequest
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
NSString *filePath = [cacheDirectory
stringByAppendingPathComponent:@"recording.wav"];
[request addFile:filePath forKey:@"data"];
[request startAsynchronous];
Even with this extremely simple implementation, I'm still experiencing
timeouts on every request (I even bumped the timeout to 60s).
I'm using v1.7-56 2010-08-30, Xcode 3.2.4, and OS X 10.6.4. I went so
far as to create an entirely new project with the above lines in
didFinishLaunchingWithOptions still to no avail. I also had a
coworker build against 4.0 (I'm using 4.1), this produced the same
timeout. Recording.wav is on the FS...it's about 400K. The only time
I am not getting timeouts is when the entire file is able to be
transfered within the first two measurement periods...this happens
when I'm posting to a local web server. When posting to the web,
however, my transfer rates are slower, and the post ends up timing
out.
On thing that does seem to be interesting is that when looking at the
output from 'sudo tcpdump -i en1 -s 0 -A tcp port 80', the remote web
service is actually sending a response. For some reason, ASI does not
seem to be recognizing this and thus the timeout.
Is there anything I'm overlooking here? Please let me know if there is
any additional information I can provide that would help determine the
cause of this issue.
Best,
-Matt Tuzzolo
> So I've spent some more time digging into this and it's very strange.
> Here's the code I'm using now to post a file:
>
> ASIFormDataRequest *request = [ASIFormDataRequest
> requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
>
> NSArray *paths =
> NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
> NSUserDomainMask, YES);
> NSString *cacheDirectory = [paths objectAtIndex:0];
> NSString *filePath = [cacheDirectory
> stringByAppendingPathComponent:@"recording.wav"];
>
> [request addFile:filePath forKey:@"data"];
> [request startAsynchronous];
>
> Even with this extremely simple implementation, I'm still experiencing
> timeouts on every request (I even bumped the timeout to 60s).
Thanks for the sample code. I am able to reproduce this issue, but only when posting to www.google.com.
I can successfully post 4MB of data to my own webserver (located on the other side of the Atlantic) without problems, but a 400KB post to www.google.com will fail - this is because of the way www.google.com closes connections for requests using methods they don't support (I think you can only use GET or HEAD) before they've finished sending data.
If you are seeing something similar posting to the actual server your requests are talking to, please post the real url (or send it to me off-list if you prefer) and I'll take a look.
Best
Ben
> just in case you are still having problems with this, I have what is
> hopefully the solution. We just went through a painful debug session
> where we were getting basically identical timeouts to what you posted
> in the start of this thread. For reference we were trying to post
> image data to a ruby site hosted on Heroku.
>
> The solution that worked for us was:
> [request setShouldAttemptPersistentConnection:NO];
>
> Give that a shot and hopefully it will solve your problem if you
> haven't solved it already.
If it's at all possible to leave persistent connections turned on, then I'd recommend it - they do provide a significant speed boost in many situations, especially if you have lots of small requests.
You might want to experiment with a lower number for persistentConnectionTimeoutSeconds - see http://allseeing-i.com/ASIHTTPRequest/How-to-use#configuring_persistent_connections for details.
Best,
Ben
Certainly if you're uploading a relatively large image file (and know
the server is not robust in it's persistent connection handling) then
disabling persistence seems like it should be a win to me. [I guess
ASIHTTPRequest would have no way to tell whether a connection was going
to work before it had sent up the whole POST request and the whole
image, so it would have to fail only a very small percentage of the time
to make trying a recycled persistent connection an improvement.]
Cheers,
Joseph
> Seeing this just triggered something in my memory - if I recall correctly the major browsers will never make a POST on a persisted connection (presumably for exactly this reason).
Ah, that's interesting.
> it would have to fail only a very small percentage of the time to make trying a recycled persistent connection an improvement.
Ok, perhaps it would make sense to match the browser behaviour. I'm guessing multiple GET requests to the same server in a short space of time are probably much more common than multiple PUT/POST requests in most apps anyway.
Best,
Ben
I guess it will vary a lot between apps. I would guess that many servers
do correctly handle POSTs on persistent connections, though it's not an
area I've looked at in any great detail.
Perhaps it might make sense to have an extra "use persistent connections
for POST" global setting that defaults to off?
Cheers,
Joseph