I call the POST method like this
let parameters = ["empId": "1", "empName": "John"]
guard let url = URL(string: "test.com") else {
return
}
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
do {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
} catch {
}
URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
if let data = data, let response = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] {
print(response)
}
}.resume()
It works. Now I need to additionally send an image to server with type image/png
with name image. How can I do that?