I am having error closing streamwriter after writing json content to the stream writer.
Following is the code i am using. Can not find what is wrong. it is writing to REST service.
WebRequest request = WebRequest.Create(String.Format("{0}/EventLog", restPath));
request.ContentType = "application/json";
request.Method = "POST";
request.ContentLength = jsonstring.Length;
System.IO.StreamWriter sw = new System.IO.StreamWriter(request.GetRequestStream());
sw.Write(jsonstring);
sw.Close();
sw.Dispose();
HttpWebResponse res = (HttpWebResponse)request.GetResponse();
Exception:”Cannot close stream until all bytes are written.”
Make sure
request.ContentLengthis really equal to the Content lenght (in bytes).This throws the same error: