title: Print Alamofire request body
body: <p>I'm using Alamofire library for connecting with an API in iOs. I have a problem in one of the connection, and I don't know if it is because of the data encoded in the body or any other thing. In order to detect my error, I'm trying to print in the console the request body for checking if I'm sending the correct data structure.</p>
  
  <p>My code is the following:</p>
  
  <pre><code>func updateUser (#user: User, completionHandler: (responseObject: User?, error: AnyObject?) -&gt; ()) {
      let parameters = [
          "_id": "\(user._id!)",
          "email": "\(user.email!)",
          "media": "\(Mapper().toJSONArray(user.media!))",
          "blogs": "\(Mapper().toJSONArray(user.blogs!))"
      ]
  
      var manager = Alamofire.Manager.sharedInstance
      manager.request(.PUT, apiUrl + "/route/to/api", parameters: parameters, encoding: .JSON)
          .responseObject{ (req: NSURLRequest, res: NSHTTPURLResponse?, user: User?, data: AnyObject?, error: NSError?) in
              if(error != nil) {
                  NSLog("Error API updateUser: \(error)")
              }
              else {
                  completionHandler(responseObject: user as User?, error: data)
              }
      }
  }
  </code></pre>
  
  <p>User is a Mappable object, since I'm using ObjectMapper combined with Alamofire. User is defined by the following code:</p>
  
  <pre><code>class User: Mappable {
     var _id: String?
     var name: String?
     var media: [Media]?
  
     init(_id: String, name: String, media: [Media]){
        self._id = _id;
        self.name = name;
        self.media = media
     }
  
     required init=(_ map: Map){
        mapping(map)
     }
  
     func mapping(map: Map){
        _id &lt;- map["_id"]
        name &lt;- map["name"]
        media &lt;- map["media"]
     }
  }
  </code></pre>
  
  <p>Media is defined like User, but with different variables.</p>
  
  <p>Also, I would like to know, in addition of printing request body, if I could include the parameters to Alimofire request in a more efficient way (something like parsing the User object and substituting it for the parameters variable)</p>
  
  <p>Any idea about my problems?</p>
  
  <p>EDIT:</p>
  
  <p>Following the suggestion of @Travis, finally I found the solution for printing the request body. Below you could find the code:</p>
  
  <pre><code>println("request body: \(NSString(data:req.HTTPBody!, encoding:NSUTF8StringEncoding) as String?)")
  </code></pre>
  
  <p>About passing as parameters an object I couldn't work it, I followed the official documentation, but I could do it.</p>