title: Replicate AFNetworking POST request with NSURLSession
body: <p>POST request with <code>AFNetworking</code>:</p>
  
  <pre><code>let urlString = "http://example.com/file.php"
  let dictionary = ["key1": [1,2,3], "key2": [2,4,6]]
  
  var error: NSError?
  let data = NSJSONSerialization.dataWithJSONObject(dictionary, options: NSJSONWritingOptions.allZeros, error: &amp;error)
  let jsonString = NSString(data: data!, encoding: NSUTF8StringEncoding)
  let parameters = ["data" :  jsonString!]
  
  let manager = AFHTTPSessionManager()
  manager.responseSerializer = AFHTTPResponseSerializer()
  manager.POST(urlString, parameters: parameters, success:
      {
          requestOperation, response in
  
          let result = NSString(data: response as! NSData, encoding: NSUTF8StringEncoding)!
  
          println(result)
      },
      failure:
      {
          requestOperation, error in
  })
  </code></pre>
  
  <p>POST request with <code>NSURLSession</code>:</p>
  
  <pre><code>let request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
  request.HTTPMethod = "POST"
  
  let bodyData = NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions.allZeros, error: &amp;error)!
  request.HTTPBody = bodyData
  request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  request.addValue("\(bodyData.length)", forHTTPHeaderField: "Content-Length")
  
  NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -&gt; Void in
      let result = NSString(data: data, encoding: NSUTF8StringEncoding)!
  
      println(result)
  }).resume()
  </code></pre>
  
  <p>On server I have:</p>
  
  <pre><code>$data = json_decode($_POST["data"], true);
  if (!$data) {
      echo "Error: Invalid POST data";
      return;
  }
  //do some stuff
  
  echo "success";
  </code></pre>
  
  <p>On second case I get "Error: Invalid POST data". What I doing wrong?</p>