1

我正在使用 sendgrid Web API 成功发送邮件,但无法将类别添加到 x-smtpapi。这是我的代码:

function getHTML (strUrl,postData)
    Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
    xmlHttp.Open "POST", strUrl, False
    xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
    xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
    'xmlHttp.AddHeader "category", "web"         
    xmlHttp.Send postData

    getHTML = xmlHttp.responseText
    xmlHttp.abort()
    set xmlHttp = Nothing   
end function

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=myusername&api_key=mykey&to=soneone@somemail.com&subject=test-1 msg&html=this is test message&from=info@zyxxxz.com&category={testweb}"))
Response.End()

我在这里检查了一些文档

但我找不到任何添加类别的方法。

编辑

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail@somemail.com&subject=test-1 msg&html=this is test message&from=info@xyzzz.com&x-smtpapi={"category":"testCategory"}"))

我需要将其发布为 JSON。如果我不放双引号x-smtpapi={"category":"testCategory"}" JSON解析器无法解析!

4

1 回答 1

1

ASP 中的双引号转义:

前任。

#Invalid
str = " She said "Hello World" to the whole group"

#valid
str = " She said ""Hello World"" to the whole group"

所以这应该可以正常工作:

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail@somemail.com&subject=test-1 msg&html=this is test message&from=info@xyzzz.com&x-smtpapi={""category"":""testCategory""}"))
于 2013-04-30T10:50:32.330 回答