maigun 回复 OK 但没有任何反应
maingun reply with OK but nothing happens
使用 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"
}
首先,我得到了 BaseAddress
not right。我不得不在 BaseAddress
.
的末尾放置一个斜杠
client.BaseAddress = new Uri("https://api.mailgun.net/v3/");
没有斜杠,我是 posting 到(注意缺少 v3
),
https://api.mailgun.net/sandboxSOMEGUIDHERE.mailgun.org/messages
整理之后,又出现了一个问题401 - ANAUTHORIZED
。在这个 的帮助下,我做到了,
var byteArray = new UTF8Encoding()
.GetBytes("api:key-withheld-till-a-verdict-has-passed");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
但 mailgun
回复 Ok
的原因仍然是个谜。为了进一步调查,我使用 Postman
到 post 到
https://api.mailgun.net/sandboxSOMEGUIDHERE.mailgun.org/messages
令我惊讶的是,Mailgun
神秘地回复了 Ok
。
使用 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"
}
首先,我得到了 BaseAddress
not right。我不得不在 BaseAddress
.
client.BaseAddress = new Uri("https://api.mailgun.net/v3/");
没有斜杠,我是 posting 到(注意缺少 v3
),
https://api.mailgun.net/sandboxSOMEGUIDHERE.mailgun.org/messages
整理之后,又出现了一个问题401 - ANAUTHORIZED
。在这个
var byteArray = new UTF8Encoding()
.GetBytes("api:key-withheld-till-a-verdict-has-passed");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
但 mailgun
回复 Ok
的原因仍然是个谜。为了进一步调查,我使用 Postman
到 post 到
https://api.mailgun.net/sandboxSOMEGUIDHERE.mailgun.org/messages
令我惊讶的是,Mailgun
神秘地回复了 Ok
。