小编use*_*639的帖子

ASP.NET 3.5中的SendGrid Web API

我正在使用SendGrid电子邮件服务通过Web API(HttpWebRequest)发送电子邮件.这是我正在使用的代码,但我收到400响应.

string url = "https://sendgrid.com/api/mail.send.xml";
string parameters = "api_user=" + api_user + "&api_key=" + api_key + "&to="                     + toAddress + "&toname=" + toName + "&subject=" + subject + "&text=" + text + "&from=" + fromAddress;

// Create Request
myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

myHttpWebRequest.Method = "POST";
// myHttpWebRequest.ContentType = "application/json; charset=utf-8";
myHttpWebRequest.ContentType = "text/xml";

CookieContainer cc = new CookieContainer();
myHttpWebRequest.CookieContainer = cc;

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] postByteArray = encoding.GetBytes(parameters);
myHttpWebRequest.ContentLength = postByteArray.Length;
System.IO.Stream postStream = myHttpWebRequest.GetRequestStream();
postStream.Write(postByteArray, 0, postByteArray.Length); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net sendgrid

4
推荐指数
1
解决办法
9767
查看次数

标签 统计

asp.net ×1

c# ×1

sendgrid ×1