I need to write a httpclient to upload a huge file to the server using http. The code
public Stream function()
{
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
request.Method = "POST";
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
return dataStream;
}
Then, I return the dataStream to the caller of this function so that the application keeps writing to the stream using write. Then once done with the writing, GetResponse is called and then the stream is closed. But I get the exception
ProtocolViolationException at System.Net.HttpWriteStream.Write() while writing to the stream.
Kindly help.