I want to send a post request but to speed things up not to download the entire page, just the head (or some smaller section of the content). I know there is a way you can do this with get requests but I need to do this with a post request. I am programming with c# and System.Net.Http. However, I am willing to use another library if its necessary.
Here is how the get request can only download headers:
var request = new HttpRequestMessage(HttpMethod.Get, url);
var getTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
And here is my current code:
var response = await client.PostAsync(url, content);
var responseString = await response.Content.ReadAsStringAsync();
You can just change HttpMethod.Get to HttpMethod.Post in your first sample, and assign to request.Content:
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = content,
};
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
Of course, calling response.Content.ReadAsStringAsync() negates the point of using HttpCompletionOption.ResponseHeadersRead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With