您好,我想从其运行推送应用中心api
。但我不知道如何制作正确的格式。
我想postasync
从这个api:https ://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications
Headers 需要的是: X-API-Token ="{api token}" 和 Content Type="application/json"
对于正文(内容),我想说:
{
"notification_content" : {
"name" : "Campaign Name",
"title" : "Expired Warning",
"body" : "You have items that almost expired"
}
}
我很难为 HttpClient 编写正确的格式。我试过这个,没有工作..
Content = new Content
{
Name = "Campaign Name",
Title = "Expired Warning",
Body = "You have items that almost expired"
};
using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) })
{
var myContent = JsonConvert.SerializeObject(data);
client.DefaultRequestHeaders.Add("X-API-Token", "{my api token}");
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
var builder = new UriBuilder(new Uri("https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications"));
HttpResponseMessage response = await client.PostAsync(builder.Uri, content);
};
但我知道这段代码:
{
"notification_content" : {
"name" : "Campaign Name",
"title" : "Expired Warning",
"body" : "You have items that almost expired"
}
}
与转换json格式不同:
Content = new Content
{
Name = "Campaign Name",
Title = "Expired Warning",
Body = "You have items that almost expired"
};
可以帮助我正确的序列化 Json 格式吗?以及 httpclient 标头和正文的正确格式?我已经找到了很多样品,但仍然不知道我想要的那个。真的很感谢你们的帮助:)