Search

Thursday, March 24, 2011

Http webrequest stream error in .NETCF?

Recently i was getting this below error in windows mobile compactframework using c#, while sending data via a request stream "Either ContentLength must be set to a non-negative number, or SendChunked set to true in order to perform the write operation when AllowWriteStreamBuffering is disabled."

then after googling i cam to know that the writing to stream is disabled in .netcf by default and we have to allow it by setting AllowWriteStreamBuffering to true below is the sample code snippet on how to do it

  private static getHTTPResp(String lnk, string data, string primid)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(lnk);
if (!String.IsNullOrEmpty(content))
{
req.Method = "POST";

//Add this line to fix the issue
req.AllowWriteStreamBuffering = true;
UTF8Encoding utf8 = new UTF8Encoding();

// some code
......
......
}

}

if you still facing the above same issue after allowing stream buffering and fixed it share the tip here so that others can get benefited

1 comments:

Joshua Smith said...

Thank you for your help in discussing about this. Great review! Also turn your attention that it needs to search for software development companies if you need mobile software developer.

Post a Comment

Other Interesting Articles



Related Article Widget by Yogith

Search Powered by Google