Ich mache eine sehr einfache postRequest, aber ich der Service antwortet mir nicht, haben Sie eine Ahnung, warum das passiert? Vielleicht mache ich etwas falsch, könntest du mir helfen? Danke im Voraus.Beitrag Anfrage antwortet nicht
Hier ist mein Code Request in postman
@IBAction func buton(_ sender: Any) {
let parameters = ["acceptPrivacyNotice": true, "name" :"xxxxx xxxxx", "email": "[email protected]", "password":"Qwerty2012", "passwordConfirm":"Qwerty2012","deviceID" : "", "isProvider" : false, "idTypeProvider": 1] as [String : Any]
guard let url = URL(string: "https://www.apps-sellcom-dev.com/Engie/api/account/register") else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("M1o2K1RVMzRHVSNteUtLOjNzSCR5LUEyKk5qOEhFRg==", forHTTPHeaderField: "Authorization")
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else {
return
}
request.httpBody = httpBody
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if let response = response {
print("Response",response)
}
if let data = data {
do {
let json = try JSONSerialization.jsonObject(with: data, options: [])
print(json)
} catch {
print(error)
}
}
}.resume()
}
Verwenden Sie 'JSONSerialization' nicht, vielleicht bearbeitet Ihr Server dieses Format nicht, versuchen Sie es mit der normalen Zeichenkette zuerst zB' key = value & ... ' – Tj3n