public class Program
{
private readonly IHttpClientFactory _httpClientFactory;
public static async Task Main(string[] args)
{
var client = _httpClientFactory.CreateClient();
var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("<username>:<password>"));
client.DefaultRequestHeaders.Add("Authorization", "Basic "+ base64String);
JObject json = JObject.Parse("{'items': [{'address': '[email protected]','createdat': {}}, {'address': '[email protected]','createdat': {}}]}");
var postData = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
var DomainId = "YOUR_domainID_PARAMETER";
var request = await client.PostAsync("https://api.mailgun.net/v3/" + DomainId + "/complaints", postData);
var response = await request.Content.ReadAsStringAsync();
Console.WriteLine(response);`
}
}
我正在尝试将“投诉”列表发布到 mailgun api。 https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Complaints/#tag/Complaints/operation/api.(*ComplaintController).InsertJSON-fm-36
我收到回复“StatusCode: 400, ReasonPhrase: 'Bad Request'”。 还有一条消息 {"message":"缺少强制参数:地址"} .
我不确定到底出了什么问题。我猜这是我的 Json。
从文档来看,当您传递包含在带有字段的对象中的数组时,它看起来需要一个数组作为输入
items
您可以尝试像这样直接发布数组:
JArray json = JArray.Parse("[{'address': '[email protected]','createdat': {}}, {'address': '[email protected]','createdat': {}}]");
然后将其转换为它的字符串表示形式,或者您也可以尝试直接使用字符串文字,如下所示:
var postData = new StringContent("[{'address': '[email protected]','createdat': {}}, {'address': '[email protected]','createdat': {}}]", Encoding.UTF8, "application/json");