i am working on push notification with onesignal .i am getting some error while requesting to web server,like HttpWebRequest-The remote server returned an error: (400) Bad Request and System.Net.WebException: Value cannot be null. Parameter name: src. any body know about this ,please help me... here is my code
using System.IO;
using System.Net;
using System.Text;
var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest;
request.KeepAlive = true;
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
request.Headers.Add("authorization", "Basic My_API_Key");
byte[] byteArray = Encoding.UTF8.GetBytes("{"
+ "\"app_id\": \"My_app_id\","
+ "\"contents\": {\"en\": \"English Message\"},"
+ "\"filters\": [{\"field\": \"tag\", \"key\": \"level\", \"relation\": \">\", \"value\": \"10\"}]}");
string responseContent = null;
try {
using (var writer = request.GetRequestStream()) {
writer.Write(byteArray, 0, byteArray.Length);
}
using (var response = request.GetResponse() as HttpWebResponse) {
using (var reader = new StreamReader(response.GetResponseStream())) {
responseContent = reader.ReadToEnd();
}
}
}
catch (WebException ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
}
System.Diagnostics.Debug.WriteLine(responseContent);