send http/2 request on windows server 2012 R2
Asked Answered
K

1

6

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?

Kurrajong answered 1/1, 2018 at 5:39 Comment(0)
I
10

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://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis

Irredeemable answered 9/1, 2018 at 21:0 Comment(1)
thanks dear @e p. it means there is no way to make it work on earlier versions?Kurrajong

© 2022 - 2024 — McMap. All rights reserved.