Hi,
I am trying below code to utilize OneSignal in my application b ut getting:
'HttpWebRequest' does not contain a definition for 'KeepAlive' and no extension method 'KeepAlive' accepting a first argument of type 'HttpWebRequest' could be found
Also getting:
'WebHeaderCollection' does not contain a definition for 'Add' and the best extension method overload 'SettersExtensions.Add(IList<Setter>, BindableProperty, object)' requires a receiver of type 'IList<Setter>'
and:
'HttpWebRequest' does not contain a definition for 'GetRequestStream' and no extension method 'GetRequestStream' accepting a first argument of type 'HttpWebRequest' could be found
and:
'HttpWebRequest' does not contain a definition for 'GetResponse' and no extension method 'GetResponse' accepting a first argument of type 'HttpWebRequest' could be found
Here is the code:
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 MDFjZWMxeZDDctWYxxxjk2YPy1c3v0k0uiMpDkaysLxTgwyZqaTctzZcDYwYWQ4Y2M0ZjE1");
byte[] byteArray = Encoding.UTF8.GetBytes("{"
+ "\"app_id\": \"6a9e00004f3593-fax05-4aaf7-9a3acd51a1-8312c3d3256e8b8a9a1\","
+ "\"headings\": {\"ar\": \"Arabic Heading\"},"
+ "\"contents\": {\"ar\": \"Arabic Message\"},"
+ "\"included_segments\": [\"All\"]}");
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)
{
DisplayAlert("Error", ex.Message, "OK");
System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
}
DisplayAlert("Notification", responseContent, "OK");
Kindly help
Thanks,
Jassim