title: How do I attach data in POST request - Swift
body: <p>How do I attach multiple data with a POST request in swift.
  As attached screen shot from postman it is working fine when select the x-<code>www-form-urlencoded</code> option
  How do I attach 5 data with the body like <code>'x-www-form-urlencoded'</code> option. </p>
  
  <p>Here the code,</p>
  
  <pre><code>var request = URLRequest(url: urlString)
          request.httpMethod = "POST"
          request.setValue("application/x-www-form-urlencoded;charset=UTF-8", forHTTPHeaderField: "Content-Type")
  
          var urlComponents = URLComponents()
          urlComponents.queryItems = [
              URLQueryItem(name: “***”, value: “***”),
              URLQueryItem(name: "***", value: "***"),
              URLQueryItem(name: "***", value: "***"),
              URLQueryItem(name: "***", value: "***"),
              URLQueryItem(name: "***", value: "***"),
          ]
          request.httpBody = urlComponents.percentEncodedQuery?.data(using: String.Encoding.utf8)
  
          let loadDataTask = URLSession.shared.dataTask(with: request) { (data, response, error) in
              if let _ =  error{
                  completion(false,error)
              }
              else if let response = response as? HTTPURLResponse{
                  if response.statusCode != 200{
                      completion(false,error)
                  }
                  else{
                      do{
                          if let parsedData = try? JSONSerialization.jsonObject(with: data!, options: []){
                              let ff = parsedData as? Dictionary&lt;String,Any&gt;
                              print(ff)
                          }
                      }
                  }
  
              }
          }//let loadDataTask
          loadDataTask.resume()
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7a6UX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7a6UX.png" alt="enter image description here"></a></p>