Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
- Subject: Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
- From: Jens Alfke <email@hidden>
- Date: Sun, 7 Mar 2010 09:28:57 -0800
On Mar 5, 2010, at 7:54 PM, Stuart Malin wrote:
> I expected the sendSynchronousRequest approach to return an NSHTTPURLResponse object without an error because, according to the docs, the synchronous method is built on top of the asynchronous methods.
Yes, but its semantics are different; it's more limited because it doesn't support a delegate. In particular, you can't do HTTP authentication with the synchronous version. Therefore, any 401 response by the server is a fatal error that gets returned to you. But in the async case, a 401 is a recoverable situation because you can implement the authentication method in the delegate API to handle it.
In general, the async API does not treat HTTP status conditions (4xx, 5xx) as errors; instead you can check for these in your didReceiveResponse method. But the synchronous version does return those as NSErrors.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden