title: How to post json data to web server
body: <p>I am new in XCode. I would like to send some data to web server which can only accept and send json data. So I tried the following code.</p>
  
  <pre><code> NSMutableDictionary *newDatasetInfo = @{
                                    @"userName":@"abc",
                                    @"passWord":@"1234",
                                    @"apiKey":@"456789"
                                    }.mutableCopy;     
       NSError *myError = nil;
      NSData *post = [NSJSONSerialization dataWithJSONObject:newDatasetInfo options:NSJSONWritingPrettyPrinted  error:&amp;myError];
  
  
  NSURLSessionConfiguration *sessionConfig=[NSURLSessionConfiguration defaultSessionConfiguration];
  sessionConfig.HTTPAdditionalHeaders=@{
                                        @"Accept":@"application/json"
                                        };
  NSURLSession *session=[NSURLSession sessionWithConfiguration:sessionConfig];   
  NSString *postdatalength=[NSString stringWithFormat:@"%lu",(unsigned long)[post length]];
  NSMutableURLRequest *request=[[NSMutableURLRequest alloc] init];
  [request setURL:([NSURL URLWithString:@"http://xx.xx.xx.xx/efg/ijk/login"])];
  [request setHTTPMethod:@"POST"];
  [request setValue:postdatalength forHTTPHeaderField:@"Content-Length"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPBody:post];
  NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"requestReply: %@", requestReply);             
  
  }];
  [postDataTask resume];
  </code></pre>
  
  <p>But after running the above code I got the below message </p>
  
  <blockquote>
    <p>POSTed JSON could not be parsed.</p>
  </blockquote>
  
  <p>Does anyone know whats the error here? Please help.</p>