Reputation: 25
Basically I'm sending a http post request using HttpClient, but the total response of the kb is roughly 60kb, however I only need to read the response url to determine the outcome, is there anyway I can just read response url rather than the entire data?
Example of the code I'm currently using
string URI = "example.com";
var client = new HttpClient();
var response = await client.PostAsync(URI);
var content = await response.Content.ReadAsStringAsync();
string source = content.ToString();
return source;
What this does is return the body content of " Example.com " but I later realised I wouldn't need to read the body content for a string to determine the outcome, but just simply get the response urls.
I assume this would decrease the size of the request drastically if I'm able to receive the response url of the post request without receiving the body content or other content.
Upvotes: 0
Views: 1954
Reputation: 23208
Try to use HttpCompletionOption
with proper overload of SendAsync
method and rewrite your code like
var request = new HttpRequestMessage(HttpMethod.Post, url);
var response = await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
Upvotes: 1