发送POST HttpWebRequest和don';不需要接收响应

本文关键字:不需要 响应 POST HttpWebRequest don 发送 | 更新日期: 2023-09-27 18:26:04

我通过以下方式发送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,不想收到回复。它浪费时间和带宽。有什么可以做的吗?

非常感谢!

发送POST HttpWebRequest和don';不需要接收响应

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