我已经设置了一个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在确切的实现中相当挑剔,但也许我在这里缺少其他东西?
雨果
答案 0 :(得分:1)
Sendgrid需要表单输入(不是JSON)
这样可行:
toString()