Is HttpWebRequest.GetResponse required to complete POST?

For POST requests using HttpWebRequest, when I write to the request stream, at what point is the data sent? Is this when I close the request stream or when I call GetResponse? Is a GetResponse call required?

The .net documentation does not seem to be very clear what is actually happening.

Here is the code that interests me:

HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; request.ContentLength = jsonData.Length; request.ContentType = "application/json"; Stream requestStream = request.GetRequestStream(); requestStream.Write(jsonData, 0, jsonData.Length); requestStream.Close(); var response = request.GetResponse() as HttpWebResponse; 

Thanks!

+8
source share
2 answers

Yes, a GetResponse call GetResponse necessary not only for a POST request, but also for GET, HEAD requests. The request / data is sent the moment you call GetResponse .

+2
source

Run the sniffer and set a breakpoint on requestStream.Close(); , and you will see that this request is executed when GetResponse() called.

+1
source

All Articles