views:

55

answers:

4

Hello,

I would like to know two things about the following code:

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);

Here my two questions: - What is exactly a stream? - The line myWriter.Write sends an Http Packet with the post information or to do that i have to use a method of HttpWebRequest class?

Thanks so much. Best Regards. Jose

+1  A: 

A stream in .NET can be regarded as kind of a buffer.
It is used in file/http/memory IO

Lars Mæhlum
+1  A: 

The stream in this case is a buffer which will be sent over network. This buffer is sent when you use GetResponse function

Sergej Andrejev
+1  A: 

As already stated a Stream is the usual .NET equivalent of a buffer. It's also almost always used when doing any sort of IO, be it files, pipes, network. Usually to work with a stream you use either StreamReader or StreamWriter.

Your method should be sending a packet correctly. To read a response you would do a similar operation with GetResponseStream.

C. Ross
Then the Write method of the stream sends the post information to the url... Now clear.Thanks a lot.
Josemalive