Question about HttpWebRequest class in .net
I would like to know two things about the following code:
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objReque开发者_运维问答st.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?
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
.
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
http://msdn.microsoft.com/fr-fr/library/system.net.webresponse.getresponsestream%28VS.80%29.aspx
精彩评论