title: -[NSURLRequest sendSynchronousRequest:returningResponse:error:] getting back HTTP headers
body: <p>I'm trying to pull out HTTP Headers and an HTTP Response Code from a synchronous HTTP request on the iPhone. I generally don't have any issues doing this with asynchronous requests, although a bit of trouble here. The HTTP Response Headers are null and HTTP Status Code is 0. Web server is configured proper and I can retrieve the details I need in an asynchronous requests. Here's my code copied out to a command line program:</p>
  
  <p>Problem #1: [httpResponse allHeaderFields] returns nil.<br>
  Problem #2: [httpResponse statusCode] returns 0.</p>
  
  <p>Am I wrong in understanding that if there is an error, which I'm now seeing as: Error Domain=NSURLErrorDomain Code=-1012 UserInfo=0x14b100 "Operation could not be completed. (NSURLErrorDomain error -1012.)", that I do not get access to http response headers/status code? </p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  int main (int argc, char *argv[])
  {    
  
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      NSString *urlStr = @"http://tmp/myscript.php";
      NSString *postBody = @"foo=bar";   
      NSMutableURLRequest *request;
      NSData *postData = [postBody dataUsingEncoding:NSASCIIStringEncoding];
      NSError *error;
      NSURLResponse *response;
      NSHTTPURLResponse *httpResponse;
      NSData *dataReply;
      id stringReply;
  
      request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlStr]];
  
      [request setHTTPMethod: @"POST"];
      [request setHTTPBody:postData];
      [request setValue:@"text/xml" forHTTPHeaderField:@"Accept"];
      [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];  
  
      dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
      stringReply = (NSString *)[[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
      // Some debug code, etc.
      NSLog(@"reply from server: %@", stringReply);
      httpResponse = (NSHTTPURLResponse *)response;
      int statusCode = [httpResponse statusCode];  
      NSLog(@"HTTP Response Headers %@", [httpResponse allHeaderFields]); 
      NSLog(@"HTTP Status code: %d", statusCode);
      // End debug.
  
      [[NSRunLoop currentRunLoop] run];
      [pool release];
      return 0;
  } 
  </code></pre>