title: How to send a POST request through Swift?
body: <p>I have my controller like this - </p>
  
  <pre><code>def create
     if (@user = User.find_by_email(params[:email])) &amp;&amp; @user.valid_password?(params[:password])
        render json: @user.as_json(only: [:email,:authentication_token]),status: :created
     else 
        render json:('Unauthorized Access')
     end  
  end 
  </code></pre>
  
  <p>When I use Postman to make this request, I choose Body, and form data and adds in the email and password. And this WORKS</p>
  
  <p><a href="https://i.stack.imgur.com/mrGVT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mrGVT.png" alt="enter image description here"></a></p>
  
  <p>How to use swift to do the same? This is what I have tried </p>
  
  <pre><code>let url = URL(string: "http://localhost:3000/api/v1/user_serialized/")
  
  let config = URLSessionConfiguration.default
  
  let request = NSMutableURLRequest(url: url!)
  
  request.httpMethod = "POST"
  
  let bodyData = "email=Test@test.com&amp;password=Test1234"
  
  request.httpBody = bodyData.data(using: String.Encoding.utf8);
  
  let session = URLSession(configuration: config)
  
  let task = session.dataTask(with: url! as URL, completionHandler: {(data, response, error) in
      let json = JSON(data:data!)
  
      debugPrint(json)
  })
  
  task.resume()
  </code></pre>