title: iOS NSURLConnection POST error handling
body: <p>So for an iOS client of mine, I'm initiating a POST to upload a big chunk of data (say, 30MB), via:</p>
  
  <pre><code>[[NSURLConnection connectionWithRequest:req delegate:self] retain];
  </code></pre>
  
  <p>However, I need to handle the case where the URL is bad - say, one that returns a 404.  The problem is, my <code>didSendBodyData</code> delegate method is called over and over, just like it should be assuming the URL is correct, in chunks of 32k worth of data, until it hits the 30MB total file size.  I'm actually doing calculations in this method to show and display a progress bar, and even with an invalid URL, it looks and acts like it's transferring the whole file (I'm not sure what's really going on under the covers - it can't actually be doing anything, the URL resolves to a 404!)</p>
  
  <p>THEN, after 20 seconds of supposed uploading, my <code>didReceiveResponse</code> delegate method is finally called, where I can check the NSURLResponse and see that a 404 was served up.  Why does it seem like it transfers the entire file before I'm able to get any kind of error?  Using <code>[NSURLConnection connectionWithRequest]</code>, how can I know this was a 404 before it actually does anything?  Is there anyway to tell in the <code>didSendBodyData</code> method, or any other way to tell earlier than what I'm seeing?</p>
  
  <p>An even bigger problem is, I let you limit the upload time, so it stops after x number of seconds, at which point I cancel the connection (in the middle of the <code>didSendBodyData</code> method), so doing that there's seemingly no way to know anything even went wrong with the URL.</p>
  
  <p>It seems like this should have a ridiculously easy solution, but I'm not seeing it.  Thanks for any help.</p>