views:

22

answers:

1

Setting NSMutableURLRequest with setHTTPMethod:@"HEAD", as i only want the HEAD information, and using NSURLConnection with sendSynchronousRequest, as i need the thread to block until the info is retrieved, all works well until URL redirect occurs. It appears that synchronousRequest uses a GET request after it encounters a redirect and downloads the content in the background (Not what i want). Need someone to shine some light on this. Either how to do synchronous request of just the HEAD after redirect or how to block NSOperation (where an NSURLConnection is used) until NSURLConnection asynchronously fetches the header information.

Thanks

A: 

You need to instantiate an NSURLConnection and use it with a delegate. I thought by default redirects did the right thing, but if not, implement -connection:willSendRequest:redirectResponse: to ensure the new request is a HEAD.

You can either:

  • Implement this on the main thread
  • Subclass NSOperation to be "concurrent" and run the connection asynchronously there
  • Run the runloop until the connection finishes, creating the equivalent of a synchronous connection
Mike Abdullah
Used asynchronous connection and used a runloop until the connection finishes. It's a pain since setting up synchronous connection is so much nicer and easier.
MikeM