title: Sending form data via HTTP Post [Objective C]
body: <p>I have a form data from an iphone app that needs to send HTTP Post variables to a URL.</p>
  
  <p>The thing is, I've been told not to use setHTTPBody, but am unsure of how else to do it as every example I see uses setHTTPBody; even those that use POST methods.</p>
  
  <p>To make things matters a little more complicated, the URL/webpage requires a <code>submit=true</code> and <code>action=enquiry</code> in the post variables.</p>
  
  <p>Here's what I have so far.</p>
  
  <pre><code>NSString *formContactName   = [self contactName];
  NSString *formEmail     = [self email];
  NSString *formPhone     = [self phone];
  NSString *formComments      = [self comments];
  
  // The above data is fine, as explored here.
  NSLog(@"formContactName = %@", formContactName);
  NSLog(@"formEmail = %@", formEmail);
  NSLog(@"formPhone = %@", formPhone);
  NSLog(@"formComments = %@", formComments);
  
  // Setup request
  NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
  [request setURL:[NSURL URLWithString:advertURL]];
  [request setHTTPMethod:@"POST"];
  
  // set headers
  NSString *contentType = [NSString stringWithFormat:@"text/plain"];
  [request addValue:contentType forHTTPHeaderField:@"Content-Type"];
  
  // setup post string
  NSMutableString *postString = [[NSMutableString alloc] init];   
  [postString appendFormat:@"contactname=%@", formContactName];
  [postString appendFormat:@"&amp;email=%@", formEmail];
  [postString appendFormat:@"&amp;phone=%@", formPhone];
  [postString appendFormat:@"&amp;comments=%@", formComments];
  [postString appendFormat:@"&amp;submit=yes"];
  [postString appendFormat:@"&amp;action=enquiry"];
  
  // I've been told not to use setHTTPBody for post variables, but how else do you do it?
  [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
  
  // get response
  NSHTTPURLResponse *urlResponse = nil;
  NSError *error = [[NSError alloc] init];
  
  NSData *responseData = [NSURLConnection sendSynchronousRequest:request 
                           returningResponse:&amp;urlResponse 
                                       error:&amp;error];
  
  NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  
  
  NSLog(@"Response code: %d", [urlResponse statusCode]);
  if ([urlResponse statusCode] &gt;=200 &amp;&amp; [urlResponse statusCode] &lt;300)
  {
  NSLog(@"Response ==&gt; %@", result);
  }
  
  [result release];
  [error release];
  </code></pre>
  
  <p>I always get a 200 result, which is good. But the response back indicates that the Post variables are not getting through.</p>
  
  <p>The response back has a field in it called "enquirysent" and its always blank.  If the Post variables are successful, it should return a "1" or true statement.</p>
  
  <pre><code>"enquirysent": ""
  </code></pre>
  
  <p>Therefore, my question is: How do I force the HTTP-POST variables in the above request?</p>
  
  <p>Thanks.</p>