• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSURLConnection Asynchronous vs. Synchronous Asymmetry
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSURLConnection Asynchronous vs. Synchronous Asymmetry


  • Subject: NSURLConnection Asynchronous vs. Synchronous Asymmetry
  • From: Stuart Malin <email@hidden>
  • Date: Fri, 5 Mar 2010 22:54:45 -0500

I haven't been able to find any documentation or relevant Web results regarding a situation I'm experiencing:

I get different 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.

The particular request results in an HTTP 401 response (Not Authorized).

When I execute asynchronously:
	1a) -connection:didReceiveResponse: is invoked and supplies an NSHTTPURLResponse object
	1b) the NSHTTPURLResponse object reports the HTTP result of 401 vis -statusCode.
	2) -connection:didReceiveData: does receive data
	3) -connection:didFailWithError is NOT invoked.

When I execute synchronously with -sendSynchronousRequest:returningResponse:error:
	1) the method does return the same data as the async
	2) but: no response is returned
	3) and: an NSError is returned, with the code of -1012 (which is NSURLErrorUserCancelledAuthentication as defined in NSURL.h)

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. 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? incorrect understanding? or should I be getting similar/identical results, and so look for a bug?

Thanks for any advise...

_______________________________________________

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

  • Follow-Ups:
    • Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
      • From: Jens Alfke <email@hidden>
    • Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: [NSTableview] can't make selected text stay black
  • Next by Date: Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
  • Previous by thread: RE: NSTextField controlTextDidEndEditing
  • Next by thread: Re: NSURLConnection Asynchronous vs. Synchronous Asymmetry
  • Index(es):
    • Date
    • Thread