Sosi
Sosi

Reputation: 2578

Question about HttpWebRequest class in .net

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 are 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?

Upvotes: 1

Views: 185

Answers (4)

C. Ross
C. Ross

Reputation: 31848

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.

Upvotes: 1

Sergej Andrejev
Sergej Andrejev

Reputation: 9403

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

Upvotes: 1

Lars Mæhlum
Lars Mæhlum

Reputation: 6102

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

Upvotes: 1

Related Questions