Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set HTTP protocol version in HttpClient

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?

like image 452
mysticcode Avatar asked Jan 22 '15 19:01

mysticcode


People also ask

Where is HTTP set?

HTTP version is sent as a header in every request, so it is set in the message sent by System. Net. Http.

Does HttpClient support http2?

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.

What is C# HttpClient?

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.


1 Answers

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);
like image 67
Yuval Itzchakov Avatar answered Sep 21 '22 06:09

Yuval Itzchakov