I'm trying to send a push notification using the ionic push notifications api, using c# with WebApi. The python example from ionic website is working perfectly, but I can't get it working in c#, although it seems that the requests are the same. This is my code:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://push.ionic.io/api/v1/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("X-Ionic-Application-Id", IONIC_APP_ID);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var keyBase64 = "Basic " + IONIC_PRIVATE_KEY_BASE_64;
client.DefaultRequestHeaders.Add("Authorization", keyBase64);
client.DefaultRequestHeaders.Add("Accept-Encoding", "identity");
//client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var response = client.PostAsJsonAsync("push", json).Result;
if (response.IsSuccessStatusCode)
{
int a = 6;
}
}
I keep getting bad request (400), with no further explanation.
See Question&Answers more detail:os