【发布时间】:2017-09-18 11:49:20
【问题描述】:
使用x-www-from-urlencoded 和基本身份验证在Postman 上一切正常。现在想弄脏我的手,我只得到状态代码 200,mailgun 上什么都没有,没有记录日志。
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.mailgun.net/v3");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("api", "key-withheld-till-a-verdict-has-passed");
var msg = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("from",
$"Excited User <mailgun@sandboxSOMEGUIDHERE.mailgun.org>"),
new KeyValuePair<string, string>("to","approved-to-receive@mailgun"),
new KeyValuePair<string, string>("subject", "Test Please Do Not Reply"),
new KeyValuePair<string, string>("text","Thanks for borrowing me your inbox")
};
var request = new HttpRequestMessage(HttpMethod.Post,
"sandboxSOMEGUIDHERE.mailgun.org/messages");
request.Content = new FormUrlEncodedContent(msg);
var response = await client.SendAsync(request);
// I get 200 status code
var result = await response.Content.ReadAsStringAsync();
//I get result = "Mailgun Magnificent API"
}
【问题讨论】:
-
这似乎不是正确的反应。您确定您使用的是正确的 URL/API 端点吗?
-
我用
Postman测试过,一切都很完美。 -
查看here 并记录您的请求。查找 postman 请求和 c# 请求之间的差异。
标签: c# dotnet-httpclient mailgun