I want to encode my JSON to application/x-www-form-urlencoded
var req = URLRequest(url: url)
req.httpMethod = "POST"
req = JsonHelper.defineCommonHeaders(request: req)
var headers = req.allHTTPHeaderFields ?? [:]
headers["Content-Type"] = "application/x-www-form-urlencoded"
print(headers)
do {
let jsonData = try encoder.encode(self)
let jsonString = String(data: jsonData, encoding: .utf8)!
req.httpBody = jsonData as Data
print ("httpBody is: ", jsonString)
} catch {
//TODO:error handling
}
sending my JSON from Postman is fine, however sending from Swift 4 does not work. I quess I need to encode empty key somewhere. There is great example POST request using application/x-www-form-urlencoded but it does not cover how to do it in Swift 4. What I have to change?