我正在尝试使用带有 http post 请求的 Mailjet API v3 发送电子邮件,但收到错误 400。
我在 Javascript 中成功使用了完全相同的主体,但我猜错误 400 与它有关...
有任何想法吗 ?
var recipients = [Any]()
recipients.append(["Email": "email@gmail.com"])
var body: [String: Any] = [
"FromEmail": "anEmail@gmail.com",
"FromName": "Me",
"Subject": "YEEES",
"Text-part": "Greetings from IOS ;)",
"Recipients": recipients
]
var request = URLRequest(url: self.apiURL)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Authorization", forHTTPHeaderField: "Basic <keysInBase64>")
do {
request.httpBody = try JSONSerialization.data(withJSONObject: body, options: [])
}
catch {
print("error during JSON serialization")
dump(error)
return
}
let session = URLSession.shared
let task = session.dataTask(with: request, completionHandler: { (data, response, error) in
print(error)
print(response)
print(data)
})
task.resume()