Send HTTP 2.0 Request to App Service using C#
Published Jan 21 2024 11:31 PM 1,992 Views

Azure App Service supports HTTP 2.0. The major advance of HTTP/1.1 was the use of persistent connections to service multiple requests in a row. In HTTP/2, a persistent connection can be used to service multiple simultaneous requests. 

 

This blog will demonstrate how you can send HTTP 2.0 Request to app service for testing using C#:

 

Step 1:

Go to > App Service > Configuration > Enable HTTP 2.0

AmritpalSinghNaroo_1-1705674903359.png

 

Step 2:

Create a .Net Core Console Application / Web Application as per requirement . In this example I have taken a .Net Core Console Application:

 

 

var client = new HttpClient() { BaseAddress = new Uri("https://<>.azurewebsites.net") };

            Console.WriteLine("Sending HTTP 2.0 Request.");

            // HTTP/2 request
            using (var request = new HttpRequestMessage(HttpMethod.Get, "/") { Version = new Version(2, 0) })
            using (var response = await client.SendAsync(request))
                Console.WriteLine(response);

 

 

The HTTPClient class has DefaultRequestVersion property with which you can set the default version of the requests as below:

 

 

var SecondRequest = new HttpClient()
            {
                BaseAddress = new Uri("https://<>.azurewebsites.net"),
                DefaultRequestVersion = new Version(2, 0)
            };

            // HTTP/2 is default
            using (var response = await SecondRequest.GetAsync("/"))
                Console.WriteLine(response);

 

 

You should be able to see a successful HTTP Response once the code executes:

 

AmritpalSinghNaroo_2-1705675068921.png

 

For more information you can refer the below documents:

 

If you have any other questions, feel free to comment below!

Version history
Last update:
‎Jan 21 2024 11:31 PM
Updated by: