Send HTTP 2.0 Request to App Service using C#

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.

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



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://<>") }; 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://<>"), 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:




For more information you can refer the below documents:


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

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.