为什么 Android 的 HttpUrlConnection 不支持 HTTP/2? [英] Why HTTP/2 is not supported by Android's HttpUrlConnection?

查看:106
本文介绍了为什么 Android 的 HttpUrlConnection 不支持 HTTP/2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现 Android 推荐的 http 客户端 HttpUrlConnection 不支持 HTTP/2.

I just found out that Android's recommended http client HttpUrlConnection doesn't support HTTP/2.

有什么特别的理由不在 Android 上使用 HTTP/2?

Is there a specific reason not to use HTTP/2 on Android?

推荐答案

如果你想利用 HTTP/2,你可以使用 OkHttp:

You can use OkHttp if you want to take advantage of HTTP/2:

https://github.com/square/okhttp

无论如何它都优于 HttpUrlConnection.如果您正在做任何复杂的事情,例如从 Web API 获取复杂的 JSON 响应,我建议您使用 Retrofit:

It's superior to HttpUrlConnection anyway. If you're doing anything at all complicated, like getting complex JSON responses from a web API, I'd recommend Retrofit:

https://square.github.io/retrofit/

这篇关于为什么 Android 的 HttpUrlConnection 不支持 HTTP/2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆