Tiang
Tiang

Reputation: 57

Send POST HttpWebRequest and don't need to receive response

I send a POST request by 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 request to WebServer and I don't want to receive reponse. It wastes time and bandwidth. Are there anyway to do that?

Thank you very much!

Upvotes: 4

Views: 1257

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038940

No, there's no way. The HTTP protocol is two way. It is a request/response protocol. You need to call the GetResponse method if you want to send the request that you prepared earlier.

Upvotes: 2

Related Questions