What am i doing wrong or is it a bug?

  • Thread starter Thread starter doolaard
  • Start date Start date
D

doolaard

I created the following code:

string postName = @"dutchnomad";
string postPword = @"dotnet";

FileStream fs = new
FileStream(selectImageOpenFileDialog.FileName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] wavFile =
br.ReadBytes(Convert.ToInt32(fs.Length));
string aString = System.Convert.ToBase64String(wavFile,
0, wavFile.Length);

HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(myUrl);
myHttpWebRequest.Method = "POST";
myHttpWebRequest.AllowWriteStreamBuffering = true;

string postData = @"postName=" + postName;
postData += (@"&postPword=" + postPword);
//postData += ("&myimg=" + aString);
postData += ("&imgText=" + DateTime.Now.ToString());

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);

// Set the content type of the data being posted.
myHttpWebRequest.ContentType =
"application/x-www-form-urlencoded";

// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;

Stream newStream = myHttpWebRequest.GetRequestStream();

newStream.Write(byte1, 0, byte1.Length);

WebResponse result = myHttpWebRequest.GetResponse();

Stream receiveStream = result.GetResponseStream();

This code was created for Windows mobile 5. when I run the application
I get an exception at the moment when

WebResponse result = myHttpWebRequest.GetResponse();

gets executed:

An unhandled exception of type 'System.Net.ProtocolViolationException'
occurred in System.dll

No additional informtation available for the exception

Any idea what is wrong here?
 
Ok,

found it myself. before you can perform the GetResponse you must close
the stream that was used for writing the request

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top