Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTP/2与OkHttp3和OKhttp2_Java_Android_Retrofit2_Okhttp3_Http2 - Fatal编程技术网

Java HTTP/2与OkHttp3和OKhttp2

Java HTTP/2与OkHttp3和OKhttp2,java,android,retrofit2,okhttp3,http2,Java,Android,Retrofit2,Okhttp3,Http2,我花了很多时间在OkHttp3上实现HTTP/2支持,但我的想法都没有了 如何检查它是否工作: 正在签入access.log哪个协议使用连接到服务器的客户端: 浏览器:“GET/favicon.ico HTTP/2.0”200 382https://server.com “Mozilla/5.0(X11;Linux x86_64)” Android客户端:'GET/api/v2/…HTTP/1.1“200 3717”-“Android…” 我使用的是: 带有nginx/1.10.2和https的

我花了很多时间在OkHttp3上实现HTTP/2支持,但我的想法都没有了

如何检查它是否工作: 正在签入access.log哪个协议使用连接到服务器的客户端: 浏览器:
“GET/favicon.ico HTTP/2.0”200 382https://server.com “Mozilla/5.0(X11;Linux x86_64)”
Android客户端:
'GET/api/v2/…HTTP/1.1“200 3717”-“Android…”

我使用的是: 带有
nginx/1.10.2和https的服务器
JAVA_VERSION=“1.8.0_76”
Android版本=“6.0.1

格雷德尔先生

compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
...
我如何使用: 我试过的 我发现我需要将Jetty ALPN jar添加到我的bootclasspath中。 因此,我刚刚在build.gradle(项目)中添加了以下行:

我尝试了来自的所有alpn引导版本:但没有,甚至错误消息

我还尝试添加build.gradle
编译(“org.mortbay.jetty.alpn:alpn boot:VERSION\u NUMBER”)
,但版本7*仍然没有错误,无法工作。 在版本8*中,我在构建应用程序时出现以下错误:

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
添加targetCompatibility='1.7'和sourceCompatibility='1.7'仍然是空的


提前感谢您的帮助

alpn引导仅用于标准(桌面/服务器)JVM。它不能与Android设备一起工作

在这种情况下,对bootclasspath的更改是一个运行时选项,而不是编译器参数

AFAIK应该可以在Android上自动处理https请求

n、 b.我也看到了同样的情况,一个基于okhttp的测试客户端,为你的站点获取http/1.1,但为twitter获取http/2

$ oksocial --debug -i https://api.twitter.com/robots.txt 2>&1  | grep protocol
11:30:28.849    protocol: h2

$ oksocial --debug -i https://debug.api.heyyka.com/api/v1/dev/err 2>&1 | grep protocol
11:30:45.381    protocol: http/1.1
我认为在您的案例中,您依赖的是NPN而不是ALPN,okhttp不支持ALPN

$ nghttp -v https://debug.api.heyyka.com/api/v1/dev/err
[  0.189] Connected
[  0.362][NPN] server offers:
          * h2
          * http/1.1
The negotiated protocol: h2

我知道我应该在服务器端寻找原因,对吗?我认为这是我用openssl-1.0.2+支持重新编译nginx的最相关链接,它现在就可以工作了。android代码没有任何变化。非常感谢@YuriSchimke!
$ oksocial --debug -i https://api.twitter.com/robots.txt 2>&1  | grep protocol
11:30:28.849    protocol: h2

$ oksocial --debug -i https://debug.api.heyyka.com/api/v1/dev/err 2>&1 | grep protocol
11:30:45.381    protocol: http/1.1
$ nghttp -v https://debug.api.heyyka.com/api/v1/dev/err
[  0.189] Connected
[  0.362][NPN] server offers:
          * h2
          * http/1.1
The negotiated protocol: h2