[英]Send POST request from webapi c# to onesignal url
I'm very new on this and I need some help. 我对此很陌生,需要一些帮助。 I'm trying to send a notification from my webapi to my app. 我正在尝试将通知从我的webapi发送到我的应用程序。 To do this a need just send a post to the url(" https://onesignal.com/api/v1/notifications ") with some informations (Header from authorization and content-type). 为此,只需将带有一些信息(来自授权和内容类型的标题)的帖子发送到url(“ https://onesignal.com/api/v1/notifications ”)。 But when I send the post it takes a long and and I just get The operation timeout has been reached , no message errors that could help me. 但是,当我发送帖子时花了很长时间,并且我刚收到操作超时已到达 ,没有消息错误可以帮助我。 I tryed the code from onesignal's documentation from asp.net solutions but isn't worked for me. 我尝试了来自asp.net解决方案的onesignal文档中的代码,但不适用于我。 Anyone can help? 有人可以帮忙吗? Or just help how can I trace the error with my requisiton? 或者只是帮助我如何用我的需求跟踪错误? After try the code from onesignal's documentation I decided use the following code(both codes had the same behavior): 在尝试了onesignal文档中的代码后,我决定使用以下代码(两个代码的行为相同):
using (var client = new HttpClient())
{
var url = new Uri("https://onesignal.com/api/v1/notifications");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "Rest ID");
var obj = new
{
app_id = "APP ID",
contents = new { en = "English Message" },
included_segments = new string[] { "All" }
};
var json = JsonConvert.SerializeObject(obj);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
}
For some reason is taking a long time to send a notification and return some response for me. 由于某些原因,发送通知并返回一些响应需要花费很长时间。 So I increase the timeout to wait the response and don't get a task cancelled. 因此,我增加了等待响应的超时时间,并且没有取消任何任务。 Hope help someone. 希望可以帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.