locked
How to set WinRT Post HttpWebRequest timeout in windows 8.1 store app

    Question

  • Hello,

    I have gone through this post but there is no solution for my question.

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/d9aa441e-3778-4f62-b3a7-15909881f0ac/http-request-exceeds-allotted-timeout-of-59-seconds

    but I am still not clear about how to set timeout in windows 8.1 Httpwebrequest post method..

    in previous post then mention something else which is not relevant to my problem..

    I have HttpWebRequest method as a Post type and I am looking defualt timeout is there or not..?

    if it is not there then how could I can set timeout..

    her is my sample method..

            /// <summary>
            /// Post method for request and responce for every method 
            /// </summary>
            /// <param name="model">Class objcet</param>
            /// <param name="methodName">method name for e.g essayFeedbackRequest</param>
            /// <returns></returns>
            public static async Task<string> HttpWebRequestResponseGetLibraryProgress(object model, string methodName)
            {
            callAgain:
                string responseResutl = string.Empty;
                try
                {
                    var webRequest = (HttpWebRequest)WebRequest.Create(GlobalData.PedAPI + methodName);
                    webRequest.Method = "POST";
                    webRequest.ContentType = "application/json; charset=utf-8";
                    var Serialized = SerializeDeserialize.Serialize(model);
                    string finalSerialized = Serialized;
                    using (StreamWriter sw = new StreamWriter(await webRequest.GetRequestStreamAsync()))
                    {
                        sw.Write(finalSerialized);
                    }
    
                    HttpWebResponse httpWebResponse = await webRequest.GetResponseAsync() as HttpWebResponse;
                    using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
                    {
                        if (httpWebResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
                        {
                            string messageresult = String.Format("POST failed. Received HTTP {0}", httpWebResponse.StatusCode);
                        }
                        responseResutl = sr.ReadToEnd();
                    }
                    return responseResutl;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The request was aborted: Could not create SSL/TLS secure channel."))
                        goto callAgain;
                    throw ex;
                }
            }
    

    thank you..


    Jitendra Jadav

    Wednesday, December 10, 2014 10:48 AM

Answers