Read Web Request Message during 500-Internal Server Error

How to parse and get the “HttpWebRequest” response message when the response status is “500 Internal Server Error”?

sivasankari4gl | Answered# (1)
Reply For This Question
Answer(s) Posted
Read Web Request Message during 500-Internal Server Error

By reading the response stream of exception, inner message can be retrieved. Below given the code snippet.

 

catch (WebException webEx)

            {

                string exMessage = webEx.Message;

 

                if (webEx.Response != null)

                {

                    using (var responseReader = new StreamReader(webEx.Response.GetResponseStream()))

                    {

                        exMessage = responseReader.ReadToEnd();

                    }

                }

 

                //exMessage --> Exception Inner Message.

            }

Karthik G | Answered# (1)
Post Your Answer
   Please login to post your answer.
  Member Login
  Email Address  
  Password  
   Sign Up?  
  Privacy   Terms Of Use   Contact Us
© 2016 Developerin.Net. All rights reserved.
Trademarks and Article Images mentioned in this site may belongs to Microsoft and other respective trademark owners.
Articles, Tutorials and all other content offered here is for educational purpose only and its author copyrights.