加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:24:07 所属栏目:百科 来源:网络整理
导读:我通过这种方式发送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;
我通过这种方式发送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,loginDataBytes.Length);
stream.Close();
//line below is my way to send request,but it return a response.
res = (HttpWebResponse)req.GetResponse();

我只想向WebServer发送请求,我不想收到响应.它浪费时间和带宽.反正有吗?

非常感谢你!

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读