title: HTTP POST JSON Method
body: <p>Hi I need help in making a HTTP POST connection to a web service. I am totally clueless on how to do it. </p>
  
  <p>I only had experienced in making a NSURLConnection whereby I pass the required input parameters as part of the URL. Now it seems different as I am only provided a website and the request JSON body.</p>
  
  <pre><code>{
  "lastmodified":"String content",
  "passengerId":9223372036854775807,
  "password":"String content",
  "userId":"String content"
  }
  </code></pre>
  
  <p>Could anyone shed some light on this? Say the website is www.myURL/operations/AddItem.com</p>
  
  <p>EDIT - What am I doing wrong here? </p>
  
  <pre><code>NSError *theError = nil;
  NSArray *keys = [NSArray arrayWithObjects:@"userId", @"password", nil];
  NSArray *objects = [NSArray arrayWithObjects:userNameTextField.text, passwordTextField.text, nil];
  NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
  
  NSString *myJSONString =[jsonDictionary JSONRepresentation];
  NSData *myJSONData =[myJSONString dataUsingEncoding:NSUTF8StringEncoding];
  NSLog(@"myJSONString :%@", myJSONString); 
  NSLog(@"myJSONData :%@", myJSONData); 
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://153.20.32.74/11AprP306/passenger/item"]];
  [request setHTTPBody:myJSONData]; 
  [request setHTTPMethod:@"POST"];
  
  NSURLResponse *theResponse =[[NSURLResponse alloc]init];
  NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;theResponse error:&amp;theError];   
  NSLog(@"response : %@", theResponse);
  NSLog(@"error : %@", theError);
  NSLog(@"data : %@", data);
  NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  NSLog(@"string: %@", string);
  NSDictionary *jsonDictionaryResponse = [string JSONValue];
  NSLog(@"dic: %@", jsonDictionaryResponse);
  [string release];
  [theResponse release];
  </code></pre>
  
  <p>I am reading <code>string: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1 transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;title&gt;Request Error&lt;/title&gt;
      &lt;style&gt;BODY {..... 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'.</code></p>
  
  <p>Is it because I have short passed some values(lastmodified &amp; passengerId)? I have no idea why do they need these 2 parameters as this request is only creating a new account.</p>