For POST requests using HttpWebRequest, when I write to a request stream, at what point does the data get sent? Is it when I close the request stream or when I call GetResponse? Is the GetResponse call required?
The .net documentation does not seem to be very clear about what is really happening
Here’s the code I’m curious about:
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!
Yes,
GetResponsecall is must, not only for POST request but for GET, HEAD requests too. Request / data is sent at the point when you callGetResponse.