title: Post data on web server with web service
body: <p>Hello I am tying to save data on web server with a web service implemented in PHP.</p>
  
  <p>I am trying below code to do it. I am getting response from server but the data is not getting saved to server. I have wasted 5-6 hours of the day in googling and trying code given on net. But nothing seems to work :(</p>
  
  <pre><code>NSDictionary *someInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                                        txtTreasureName.text, @"name",
                                        txtDescription.text, @"description",
                                        txtMaterials.text, @"materials",
                                        @"77.3833", @"longitude",
                                        @"29.0167", @"latitude",
                                          categoryIdStr, @"categoryId",
                                        nil];
  
          NSError *error;
          NSData *jsonData = [NSJSONSerialization dataWithJSONObject:treasureInfo
                                                          options:NSJSONWritingPrettyPrinted 
                                                              error:&amp;error];    
  
          if (! jsonData) {
  
              DLog(@"Got an error: %@", error);
  
          } else {
          NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];        
          NSString *urlString = @"http://www.myurl.php";
  
          NSURL *url = [NSURL URLWithString:urlString];        
          [request setURL:url];
          [request setHTTPMethod:@"POST"];
  
          [request setValue:@"application/json"
      forHTTPHeaderField:@"Content-Type"];
  
          [request setValue:@"application/json"
      forHTTPHeaderField:@"Accept"];
  
          [request setValue:[NSString stringWithFormat:@"%d",
                             [jsonData length]]
         forHTTPHeaderField:@"Content-length"];
  
          [request setHTTPBody:jsonData];
  
  
          DLog(@"%@", request);
  
          [[NSURLConnection alloc]
           initWithRequest:request
           delegate:self];
  
  
          // Print json
          DLog(@"JSON summary: %@", [[NSString alloc] initWithData:jsonData
                                                          encoding:NSUTF8StringEncoding]);
  
          NSOperationQueue *queue = [[NSOperationQueue alloc] init];            
          [NSURLConnection sendAsynchronousRequest:request
                                                        queue:queue
                                            completionHandler:^(NSURLResponse *response,
                                                                NSData *data, NSError *error) {
  
                                                if ([data length] &amp;&amp;
                                                    error == nil) {
  
                                                    DLog(@"%@", [[NSString alloc] initWithData:data
                                                                                      encoding:NSUTF8StringEncoding]);
                                                    if ([self shouldDismiss]) {
  
                                                        [self dismissViewControllerAnimated:YES
                                                                                 completion:nil];
  
                                                    }
  
                                                }                                             
                                            }];      
  
      }
  </code></pre>