title: How to make HTTP Post request with JSON body in Swift?
body: <p>I'm trying to make an HTTP post request with a JSON body :</p>
  <p>How to be able to add an NSdictionnary to the HTTP request body.</p>
  <p>Here is my code, it doesn't seem to work properly.</p>
  <pre><code>var entry1 = Response(IdQuestion: 6510,IdProposition: 10,Time: 30)
  var entry2 = Response(IdQuestion: 8284,IdProposition: 10,Time: 30)
  Responses.append(entry1)
  Responses.append(entry2)
  
  let list = Responses.map { $0.asDictionary }
  
  let json = [&quot;List&quot;:list,&quot;IdSurvey&quot;:&quot;102&quot;,&quot;IdUser&quot;:&quot;iOSclient&quot;,&quot;UserInformation&quot;:&quot;iOSClient&quot;]
  
  let data: NSData = NSKeyedArchiver.archivedDataWithRootObject(json)
  
  NSJSONSerialization.isValidJSONObject(json)
  
  let myURL = NSURL(string: &quot;http://www.myserver.com&quot;)!
  let request = NSMutableURLRequest(URL: myURL)
  request.HTTPMethod = &quot;POST&quot;
  
  request.setValue(&quot;application/x-www-form-urlencoded&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)
  request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Accept&quot;)
  
  request.HTTPBody = data
  let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
      data, response, error in
      println(response)
      // Your completion handler code here
  }
  task.resume()
  </code></pre>