c# – 发送POST HttpWebRequest,不需要接收响应

我通过这种方式发送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发送请求,我不想收到响应.它浪费时间和带宽.反正有吗?

非常感谢你!

最佳答案 不,没有办法. HTTP协议是双向的.这是一个请求/响应协议.如果要发送之前准备的请求,则需要调用GetResponse方法.

点赞