title: Asynchronous POST to server
body: <p>The goal is to do a simple username/password authentication by querying a database. Until the connection is working decently my php destination file simply has following code:</p>
  
  <pre><code>echo "Posted: " . $_POST['email'];
  </code></pre>
  
  <p>The code to do this synchronously is this:</p>
  
  <pre><code>NSString *post = [[NSString alloc] initWithFormat:@"email=%@&amp;password=%@", self.email.text, ..]; // .. simplified keychainItem
  NSData *postEncoded = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
  NSString *postLength = [NSString stringWithFormat:@"%d", [postEncoded length]];
  
  NSURL *url = [NSURL URLWithString:@"http://eng.studev.groept.be/web2.0/a11_web02/improver/app/testPost"];
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setURL:url];
  [request setHTTPMethod:@"POST"];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPBody:postEncoded];
  
  NSError *error = nil;
  NSURLResponse *response = nil;
  NSData *encodedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
  NSString *data=[[NSString alloc]initWithData:encodedData encoding:NSUTF8StringEncoding];
  NSLog(@"Data? %@",data);
  </code></pre>
  
  <p>The correct value is shown as an echo. But when trying to do this asynchronously, I get following php error: "Undefined index: email".
  I try to start the asynchronous request with this line:</p>
  
  <pre><code>[[NSURLConnection connectionWithRequest:request delegate:self] start];
  </code></pre>
  
  <p>Then, I have the delegate method connection:didReceiveResponse, but there I cannot seem to get the data out... Or do I need another delegate method? Also, how 'safe' is it to check the result of your query by using just an echo (do I need/want a stream maybe?) ??</p>
  
  <p>Tia</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Problem related to the server, not to objective-C code. Asked a new question to reach the correct audience: <a href="https://stackoverflow.com/questions/8071149/post-remaining-empty">$_POST remaining empty</a></p>