I need to make a request to a webservice that uses HTTP version 1.0. Im using HttpClient
, But I cant see any option to set HTTP version.
Where can i set the request version?
HTTP version is sent as a header in every request, so it is set in the message sent by System. Net. Http.
You can't use HTTP/2 with HttpClient in . NET Core 2.1 or 2.2, even if you explicitly set the version in the request.
HttpClient class provides a base class for sending/receiving the HTTP requests/responses from a URL. It is a supported async feature of . NET framework. HttpClient is able to process multiple concurrent requests. It is a layer over HttpWebRequest and HttpWebResponse.
In order to set the version you'll have to create an instance of HttpRequestMessage
and set its Version
property which you pass to HttpClient.SendAsync
. You can use the helper HttpVersion
utility class:
var requestMessage = new HttpRequestMessage
{
Version = HttpVersion.Version10
};
var client = new HttpClient();
var response = await client.SendAsync(requestMessage);
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