#9 ✓resolved
Rick Moynihan

303 (See Other) Redirects issue a POST not GET

Reported by Rick Moynihan | July 15th, 2009 @ 10:44 AM

Hi,

There is a bug in the current master (commit 531adde3560f48f0fcd5df96ba3397d7c132f64b) of your iphone HTTP Library when receiving a 303 (See other) redirect using the ASIFormDataRequest class.

The situation is this:

1) Use ASIFormDataRequest to issue a HTTP Post (this works fine)

2) Server sends a 303 redirect instructing the client to perform a GET at a new location. (See RFC2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html )

3) ASI fails to reconnect, with the error "There was an error: Error Domain=ASIHTTPRequestErrorDomain Code=1 UserInfo=0x3d2feb0 "A connection failure occurred".

I have taken a look through the ASI code though as I'm very new to objective-c (only started learning it 2 days ago), I haven't been able to patch it successfully. This said the issue appears to occur around line 1026 in ASIHTTPRequest.

My naive addition at line 1026 (below) to check for a 303, and reset the requestMethod to GET sadly didn't work... Presumably because there is still saved state from the previous request in the form of formData around as the class is subclassed by ASIFormDataRequest.

            if ([self responseStatusCode] > 300 && [self responseStatusCode] < 308 && [self responseStatusCode] != 304) {
                if([self responseStatusCode] == 303){//Redirecting using 303 should should set the response method to 'GET'
                    self.requestMethod = @"GET";
                    self.postBody = nil;
                    self.postLength = 0;
                }

Thanks again for producing what otherwise seems to be a solid library!!

R.

Comments and changes to this ticket

  • Ben Copsey

    Ben Copsey July 15th, 2009 @ 01:27 PM

    Hi Rick

    Thanks very much for catching this!

    Your fix was very close to being perfect, but ASIHTTPRequest only sets the Content-Length header when there is a request body, so it was mistakenly re-using the old Content-Length header in the new request. I've just told it to clear the request headers for the new request (it will build them again, adding stuff like cookies back in, as part of setting up the new request).

    There's a new version up on GitHub now, can you let me know if this works for you?

    Thanks

    Ben

  • Rick Moynihan

    Rick Moynihan July 15th, 2009 @ 01:51 PM

    Hi Ben,

    Thanks ever so much for the quick turn around on this! We only started using the library yesterday during my first foray into objective-c and I'm glad it's now working as expected!

    I can indeed confirm that the fix addresses the issue for us!!

    R.

  • Ben Copsey

    Ben Copsey July 15th, 2009 @ 05:08 PM

    • State changed from “new” to “resolved”

    Great stuff, thanks again!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

People watching this ticket

Referenced by

Pages