0

I want to pass two values in HTTP request body. I try to do it like this but it isn't working. can anyone help me?

   guard let url = URL(string: "*****") else { return }
    let request = NSMutableURLRequest(url: url)
    request.httpMethod = "POST"
    request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

    let post: String = "cardId=\(viewModel.getCardId())&requestId=\(viewModel.getRequestId())"

    if let postData: Data = post.data(using: String.Encoding.ascii, allowLossyConversion: true) {
        request.httpBody = postData
        webView.load(request as URLRequest)
    }
Rezo Joglidze
  • 321
  • 1
  • 3
  • 15

0 Answers0