简体   繁体   中英

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?

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM