我试图做一个post请求和发送邮件与mailgun API的消息,但我似乎无法弄清楚如何在swift格式的消息数据。从使用时出现问题参数
request.setValue("Basic (base64Credentials)", forHTTPHeaderField: "Authorization")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let data = "from: Foo <info@sandbox(sandboxInfo).mailgun.org>&to: <foo@me.com>&subject:Hello&text:Testing Mailgun"
request.httpBody = data.data(using: String.Encoding.ascii)
响应:
);
"Cache-Control" = (
"no-store"
);
Connection = (
"keep-alive"
);
"Content-Length" = (
46
);
"Content-Type" = (
"application/json"
);
Date = (
"Wed, 03 Mar 2021 01:05:39 GMT"
);
Server = (
nginx
);
} }
response code = 400
data {
"message": "'from' parameter is missing"
}
我一直在尝试从mailgun访问这个API,似乎文档有点误导。当使用https://api.mailgun.net/v3/xxxxx.domain/messages时,似乎主体应该以参数的形式供API识别。