我已经设置了一个 sendgrid 帐户并使用 cUrl 对其进行了测试:
curl -v -X POST https://api.sendgrid.com/api/mail.send.json
-d "to=me@xxxxxxxxxx.com"
-d "from=noreply@xxxxxxxxxx.com"
-d "subject=Sending with SendGrid is Fun"
-d "html=and easy to do anywhere, even with CURL"
-H "Authorization: Bearer xxxxxxxxxxxxxxxxxxx"
作品:
{"message":"success"}
MarkLogic 8
现在我尝试在使用时做同样的xdmp.httpPost
事情:
// query
var payload = xdmp.quote({
"to": "me@xxxxxxxxx.com",
"from" : "noreply@xxxxxxxxxx.com",
"subject" : "dingus",
"text" : "inhoud man"
});
xdmp.httpPost("https://api.sendgrid.com/api/mail.send.json",
{
"data" : payload,
"headers" : {
"Authorization" : "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"content-type" : "application/json"
}
});
失败:
{
"code": 400,
"message": "Bad Request",
"headers": {
"server": "nginx",
"date": "Mon, 14 Mar 2016 09:55:23 GMT",
"content-type": "application/json",
"content-length": "68",
"connection": "keep-alive",
"x-frame-options": "DENY"
}
}
JSON Document
{
"errors": [
"Empty from email address (required)"
],
"message": "error"
}
一些搜索显示 sendgrid api 在确切的实现中相当挑剔,但也许我在这里遗漏了其他东西?
雨果