Windows Universal https Post Problem

Hey,
I want to make a Json Post Request with my Windows Universal App.
I have it working in my Android and IOS.

   public String DoServiceCall()
    {
        var request = (HttpWebRequest)WebRequest.Create(string.Format("{2}/{0}/{0}ServiceJson.svc/{1}", "Authentication", "Authenticate", "https://....."));

        using (MemoryStream ms = new MemoryStream())
        {
            // create the request object
            string requestString = JSONRequest;
            byte[] requestData = Encoding.UTF8.GetBytes(requestString);
            request.Method = "POST";
            request.ContentType = "application/json; charset=UTF-8";
            request.ContentLength = requestData.Length;
            request.AllowAutoRedirect = false;

            // add known cookies to request (needed for authentication)
            CookieContainer requestCookies = new CookieContainer();
            foreach (Cookie knownCookie in this._cookieCollection)
            {
                requestCookies.Add( knownCookie);
            }
            request.CookieContainer = requestCookies;

            //For getting rid of the https Problem
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            using (Stream stream =  request.GetRequestStream())
            {
                stream.Write(requestData, 0, requestData.Length);
            }
            // get response data
            HttpWebResponse response = (HttpWebResponse) request.GetResponse();

            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return (responseString);
        }
    }

The Problem is that Windows Universal does not support.
request.ContentLength = requestData.Length;
request.AllowAutoRedirect = false;
requestCookies.Add( knownCookie); //with only on Argument
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

Neither does it support.
request.GetRequestStream())
(HttpWebResponse) request.GetResponse();
But that i could fix with async
=> await request.GetRequestStreamAsync())
=> (HttpWebResponse)await request.GetResponseAsync();

But without that 4 Lines i couldn´t get it working on Windows.
Is there an Option to get it working on Windows 10 or is there an Working alternative.

Thanks

Best Answer

Answers

Sign In or Register to comment.