How to enforce URLSession to use HTTP/1.1

Hello there, I'm trying to consume graph.microsoft.com API by using URLSession. But I'm getting Error 400 from the server every time when I send a request with URLSession, but not if I use Postman for the same request. And when I examined the requests with Fiddler, I noticed that URLSession use HTTP/2, and Postman use HTTP/1.1. According to the Microsoft's documentation graph.microsoft.com supports only HTTP/1.1. As I understand URLSession decides to which version of HTTP to use during ALPN and will use HTTP/2 only if the server support it. My question is it possible the graph server to advertise itself as its support HTTP/2 and how to determinate this? Or maybe, which is more likely URLSession has bug that make it to do the wrong assumption about the HTTP/2. And most important there is there a mechanism to make URLSession to use a certain version of HTTP?

Thank you in advance, Emil

As I understand URLSession decides to which version of HTTP to use during ALPN and will use HTTP/2 only if the server support it.

Yes and no. The way this works is that URLSession lists the HTTP/2 protocol in the ALPN extension that it includes in the Client Hello message. It’s then up to the server as to whether to accept that offer or not. If it does, it returns HTTP/2 in the ALPN Next Protocol extension in the Server Hello that it sends back to the client. It should only do this if it’s willing to speak HTTP/2.

The example in the Foundation of All Knowledge™ should make this clear.

AFAIK there’s no way to tell URLSession to not offer HTTP/2 [1]. It’s really up to the server to not accept the offer if it doesn’t support it.

However, it’s quite possible that this isn’t related to HTTP/2 at all. I recommend that you use an RVI packet trace to look at the Client Hello and Server Hello messages to see what’s actually being offered and accepted.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, no good way. If this turns out to be an HTTP/2 issue, I can dig deeper into this.

How to enforce URLSession to use HTTP/1.1
 
 
Q