We’re having a problem with an apparent limitation on the size of the response we’re able to retrieve from WebException.Response.
Here is the code:
WRequest = (HttpWebRequest)HttpWebRequest.Create (UploadURL);
if (!string.IsNullOrEmpty (deliveryDetails.Login))
{
WRequest.Credentials = new NetworkCredential (deliveryDetails.Login, deliveryDetails.Password);
}
WRequest.PreAuthenticate = true;
WRequest.UserAgent = "Ops Portal 1.0";
WRequest.Method = WebRequestMethods.Http.Post;
WRequest.AllowWriteStreamBuffering = true;
WRequest.Timeout = deliveryDetails.Timeout;
WRequest.ContentType = "text/xml";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding ();
byte[] theByteArray = encoding.GetBytes (theData.ToString ());
// Set the content length header to the size of the buffer.
WRequest.ContentLength = theByteArray.Length;
Stream tempStream = WRequest.GetRequestStream ();
tempStream.Write (theByteArray, 0, theByteArray.Length);
try
{
WResponse = (HttpWebResponse)WRequest.GetResponse ();
Stream theResponseStream = WResponse.GetResponseStream (); <- this produces the entire response stream intact
�/span>
}
catch (WebException wex)
{
WResponse = (HttpWebResponse)wex.Response;
if (WResponse != null)
{
int statusCode = (int)WResponse.StatusCode;
if (statusCode == 422) // Unprocessed Entity - this is treated the same as HttpStatusCode.OK
{
Stream theResponseStream = WResponse.GetResponseStream ();ß this appears to have a limit of 65K
StreamReader theReader = new StreamReader (theResponseStream, Encoding.UTF8);
TextWriter theWriter = new StreamWriter (theResponseFileName, true);
theWriter.Write (theReader.ReadToEnd ());
theWriter.Flush ();
theWriter.Close ();
�/span>
Is there a way to access the entire response when this type of exception is thrown?
Thanks!