Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send http/2 request on windows server 2012 R2

I want to consume the APNs push service in my application so i use this code:

    var responseString = string.Empty;
    using (var request = new HttpClient(new Http2CustomHandler()))
    {
        var content = new StringContent(body);
        request.DefaultRequestHeaders.Add("authorization", $"bearer {authorization}");
        request.DefaultRequestHeaders.Add("apns-topic", topicName);
        if (!string.IsNullOrWhiteSpace(iD)) request.DefaultRequestHeaders.Add("apns-id", iD);
        if (!string.IsNullOrWhiteSpace(expiration)) request.DefaultRequestHeaders.Add("apns-expiration", expiration);
        if (!string.IsNullOrWhiteSpace(priority)) request.DefaultRequestHeaders.Add("apns-priority", priority);
        if (!string.IsNullOrWhiteSpace(collapseID)) request.DefaultRequestHeaders.Add("apns-collapse-id", collapseID);
        var result = request.PostAsync(url, content).GetAwaiter().GetResult();

        responseString = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();
    }

its working just fine on my machine(windows 10). but when i deploy the application on my server(windows server 2012 R2) it throws this exception:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: A security error occurred

is there any way to solve this problem?

like image 227
Mohammad Avatar asked Jan 01 '18 05:01

Mohammad


People also ask

How do I enable http2 on Windows?

Launch your browser from your Windows 10 or Windows Server 2016 machine and hit F12, (or go to Settings and enable F12 Developer Tools), and then switch to the Network tab. Browse to https://localhost and voila, you are on HTTP/2!

How do I make a http2 request?

The command line parameter --http2 can be used to make HTTP/2 requests, e.g., curl --http2 domain.com . Alternatively, a Docker image can be used for cURL that supports HTTP/2.

How can I tell if HTTP 2 is enabled?

Google Chrome offers a quick and easy way to check if HTTP/2 is supported on your SSL-enabled site. First, visit your site in Chrome over HTTPS. There you'll see your site listed with protocol h2, confirming your site works over HTTP/2.


1 Answers

You most probably have already discovered that it could be because HTTP/2 is only supported in Windows Server 2016 (IIS10) and Windows 10.

The version of IIS on Windows Server 2012 does not support HTTP/2.

See https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis

like image 133
e p Avatar answered Oct 13 '22 19:10

e p