我通过这种方式发送POST请求:
HttpWebResponse res = null;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "POST";
req.CookieContainer = cookieContainer;
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3";
req.ContentType = "application/x-www-form-urlencoded";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(requestCommand);
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
stream.Close();
//line below is my way to send request, but it return a response.
res = (HttpWebResponse)req.GetResponse();
我只想向WebServer发送请求,我不想收到回复。它浪费时间和带宽。反正有吗?
非常感谢!
答案 0 :(得分:2)
不,没有办法。 HTTP协议是双向的。这是一个请求/响应协议。如果要发送之前准备的请求,则需要调用GetResponse
方法。