locked
'HttpWebRequest' does not contain a definition for 'KeepAlive' RRS feed

  • Question

  • 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

    Wednesday, November 15, 2017 11:21 AM

All replies

  • Forgot to say I am using it within Xamarin app
    Wednesday, November 15, 2017 11:33 AM
  • Hi Jassim Rahma,

    If your question is more related to Xamarin, you could post a new thread in Xamarin forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, November 19, 2017 3:57 PM