Http/2 HttpClient and HPACK For APNs
Asked Answered
R

1

6

I am writing code to send notifications to the Apple push notification servers (APNs). It says in the documents that it requires HTTP/ HPACK header compression. I found the following code to use HTTP/2 with C# httpclient:

public class Http2CustomHandler : WinHttpHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        request.Version = new Version("2.0");
        return base.SendAsync(request, cancellationToken);
    }
}

using (var httpClient = new HttpClient(new Http2CustomHandler()))
{

}

Does that compress the headers that I will add to the HttpClient automatically or should I add the header data some other way?

Riker answered 26/8, 2017 at 13:21 Comment(4)
Did you ever figure out the answer? Or did you get any off this working? Thanks!Menadione
Yes, I found out that it does actually compress the headers, nothing additional required.Riker
Thanks for responding, that’s excellent to hear! I am eager to find out if you were able to get a successful iOS notification sent this way, as I have long been hoping the new http2 work in .net could help solve this. If you would be willing to share a sample or just some snippets demonstrating some core concepts, I would be glad to make a new question and award it a nice bounty...Menadione
I am also eager to hear if you managed to solve it! Struggling with this right now and we are getting an HttpRequestException "Error while copying content to a stream." Inner Exception InnerException = {"Error 12152 calling WinHttpWriteData, 'The server returned an invalid or unrecognized response'."}Camfort
G
1

Yes it does compress the headers. You don't have to do anything extra.

Grandmamma answered 28/11, 2018 at 3:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.