Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
- Subject: Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
- From: Jerry Krinock <email@hidden>
- Date: Fri, 5 Mar 2010 20:49:29 -0800
On 2010 Mar 05, at 19:54, Stuart Malin wrote:
> I haven't been able to find any documentation or relevant Web results regarding a situation I'm experiencing:
Indeed, see below.
> I get different [error] results for the same identical NSURLRequest when I execute the request using NSURLConnection's +sendSynchronousRequest versus when I execute using asynchronously by allocating an NSURLConnection's instance and calling -start on it [and an error occurs] ...
> 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.
But one can discard useful information in the process of building on top of something :)
> The asymmetry of the response is a unsettling as I'm trying to have my code work either with synchronous or asynchronous, but having to interpret results differently is making this a nuisance (especially mapping NSURL error codes back to HTTP status codes).
>
> Do I have unreasonable expectations?
Well, maybe not unreasonable in the sense of "what a reasonable person would expect", but unreasonable in light of the documentation for the error parameter of +sendSynchronousRequest...
"Out parameter used if an error occurs while processing the request."
In other words, "You're guaranteed to get an NSError of some kind". Apple could change the implementation in Mac OS 10.7 to always return error code 99999 with localized description "Sorry, Charlie".
My conclusion is that +sendSychronousRequest is OK for quick hacks or in-house apps, but if you're writing a real app and need a meaningful NSError to act upon, you need to implement your own version of it based on the asynchronous methods, and return the NSError you get from them. Mark Pauley suggests how to do that in this thread:
http://lists.apple.com/archives/Macnetworkprog/2009/Oct/msg00028.html
_______________________________________________
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