Interesting NSURLConnection quirk

You would expect this code always return a response, sometimes return data, and when there was no data, you could look at the response and the error to determine what happened. Not so! The response object is nil if it hits a NSURLErrorUserCancelledAuthentication (-1012).

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!data) NSLog(@"Network error: HTTP %i - %@", [response statusCode], error);

Changed to the code below, for now. Not sure how to deal with it long term though, may have to move away from my sendSynchronousRequest from within an NSBlockOperation technique of network queuing.

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!data || !response) NSLog(@"Network error: HTTP %i - %@", [response statusCode], error);
DMURLConnection

vectorvector:

A very very light wrapper for NSURLConnection. I wrote it, found it useful, thought that I would share. For when you need to send an HTTP post request and download some kind of response asynchronously.