【发布时间】:2022-03-08 18:57:20
【问题描述】:
我正在尝试使用 mailgun API 进行发布请求并发送消息,但我似乎无法弄清楚如何快速格式化消息数据。我上传的数据中的 from 参数存在问题。
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"
}
【问题讨论】:
-
通过找出 HTTP 状态码 400 的含义来帮助自己。
-
我知道代码的含义,它告诉我响应消息中的错误。 from 参数错误,但我不知道正确的参数是什么。
-
您必须提交所有需要的参数并正确设置MG。这个完整的例子(包括vb,net代码)可以帮助你:stackoverflow.com/questions/68150905/…
标签: swift http post request mailgun