0
votes

Our mobile apps need to make 2 different HTTPS requests at the same time. We would like to make sure that only 1 connection is used. Our server supports HTTP/2.

On iOS, everything works well: only 1 connection is established.

On Android, our app is establishing 2 different connections.

Is it possible to achieve the same also on Android?

UPDATE:

I found out the reason: Android's recommended http client HttpUrlConnection doesn't support HTTP/2!

What recommendation do you have for using HTTP/2 on Android?

1
You can try to use System.setProperty("http.keepAlive","true"); You will need to maintain the connection and take care of urlConnection.disconnect(); yourself. -- I removed my answer in order to add this comment (it will get more attention- people usually look for unanswered questions) because I am a bit uncertain about the results of this suggestion. I simply read the docs -- I have never had any issues with connections or connection pools in the past... so I really haven't dug too deep.Barns
@Barns It looks like HttpUrlConnection uses HTTP/1.1 and not HTTP/2. That might well be the reason!Daniele B
According to the docs OkHttp supports HTTP/2.Barns
but it looks like on HttpUrlConnection, it is forced to use HTTP/1.1: stackoverflow.com/questions/44122781/…Daniele B
I am certain you are correct about HttpUrlConnection, I am referring to OKHttp :: github.com/square/okhttpBarns

1 Answers

0
votes

Eventually I was able to make HTTP/2 requests on Android, by using the OkHttp library:

http://square.github.io/okhttp/

It's very disappointing that HttpUrlConnection (Android library's default http client) does not support HTTP/2, not even on the latest Android 9!

HTTP/2 support in iOS started on iOS 9, which means 2015, 3 years ago!