AsyncHTTPClient fails for MSGraph call while URLSession doesn’t

I am trying to download files using the MSGraph APP: https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/content

Using async-http-client with async/await API works 20% of the time, for the same URL. Most times however the call returns an html file containing a 503 service unavailable error, but status code is 200 OK. The same call works with URLSession, cURL and wget reliably.

I don’t even know where to start debugging a problem like this. I tried forcing HTTP/1.0, using the redirect url directly.

My guess is that maybe MSGraph doesn’t like something about my request, but then, why would the exact same call work sometimes? Plus, the only thing that the API wants is an authorization header

503 is "Service Unavailable". Are you getting Retry-After http header in the response? I don't know if those other API's handle retries automatically or not, might be the case that they do and with your MSGraph you need to do it manually.

I don’t get a retry-after header. And the status code is 200… so MSGraph seems to just think it’s sending me the right file. I thought I might have be banned by a firewall, since everything worked perfectly until a week ago. But then switching to URLSession and curl seems to fix the problem… so clearly my IP is not banned

There were also a few instances where I got the file I requested, but at the end of it the service unavailable message was appended. Thankfully a checksum of the expected file caught this

I see. If there's nothing easier I'd probably use tcpdump or Charles to see the difference in the traffic.

Weird. In a different thread over on DevForums I’m hearing that URLSession doesn’t work with that site.

Are you testing the URLSession code on an Apple platform? Or Linux? Or something else?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple