Send POST HttpWebRequest and no need to receive a response

I am sending a POST request this way:

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(); 

I just want to send a request to WebServer, and I don't want to receive a response. It spends time and bandwidth. Anyway, to do this?

Many thanks!

+4
source share
1 answer

No no. HTTP protocol is two ways. This is a request / response protocol. You need to call the GetResponse method if you want to send a previously requested request.

+2
source

Source: https://habr.com/ru/post/1398762/


All Articles