.net - WebException when reading a WebException's response stream -


I am communicating with the web server over the net. The web server throws 500 internal server errors and writes a detailed error message.

I am trying to read the error message received from a web exception, but getting another web exception is why another web application has been thrown out?

  Try {var webResponse = (HTTP Webbense) webRequest.GetResponse (); } Catch (WebException e) {if (e.Status == WebExceptionStatus.ProtocolError) {// next line throws a web exception console. WrightLine (new stream reader (E. Response. GetspoonSstream ()). ReadToEnd ()); }}  

Why is this amazing? Try out the following MSDN:

  try {// Create web requests for an invalid site. Build "Invalid site" in the Make Call with an invalid name. HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create ("Invalid Site"); // Use the received feedback for the above request (HTTP Web Response My HTTP Web Response = (HTTP Webbations) myHttpWebRequest.GetResponse ()) {myHttpWebResponse.Close (); }} (WebException e) {Console.WriteLine ("Expect to throw WebException on successful execution of this program." + "\ N \ n Expanded message:" + E. Message;); If (e.status == WebExceptionStatus.ProtocolError) {var response = ((HttpWebResponse) e.Response); Console.light line ("status code: {0}", response. StatusCode); Console.light line ("status description: {0}", feedback status description); Try {{var reader = new StreamReader (stream)) ({Var stream = response.GetResponseStream ()) {var text = reader.ReadToEnd (); Console.WriteLine (text); }}} Hold (WebException ex) {// Oh, okay, we tried}}} hold (exception e) {console. WrightLine (e.Message); }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -