.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > Possible Get Response Stream truncation
 

Possible Get Response Stream truncation

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!

Mike G II
As per http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.defaultmaximumerrorresponselength.aspx the error response is limited by default. You should be able to change the limit, though

Hope this helps.

feroze
--
My blog
  • Marked As Answer byMike G II Sunday, September 20, 2009 1:28 AM
  • Proposed As Answer byFeroze Daud Friday, September 18, 2009 8:07 PM
  •  
Feroze Daud
As per http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.defaultmaximumerrorresponselength.aspx the error response is limited by default. You should be able to change the limit, though

Hope this helps.

feroze
--
My blog
  • Marked As Answer byMike G II Sunday, September 20, 2009 1:28 AM
  • Proposed As Answer byFeroze Daud Friday, September 18, 2009 8:07 PM
  •  
Feroze Daud
Feroze, thank you so much.

Using your answer as my guide I was actually able to find:

In the web.config, after the system.web section, add the following:

<system.net>
<settings>
<httpWebRequest maximumErrorResponseLength="-1" />
</settings>
</system.net>

-1 means unlimited but you can use any value in there for the number of bytes.

Mike G II

You can use google to search for other answers

Custom Search

More Threads

• function VB.Net for download from ftp - it don't goes to end everytime
• Trim() for Encoding function
• WebClient DownloadProgressChanged event not fired when using DownloadFileAsync
• Read Client Packet
• calculate bandwidth
• Make sure data is sent... (C# TCPClient)
• check Yahoo Messenger user online status (C#)?
• How can I encryption in 128 bit file Upload and Download from Server...?
• Problem to send data to a TCPServer
• My Mail object does not support Images..How can i get it?