Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.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
Android ProtocolException:应为';:状态';标题不存在_Android_Retrofit_Retrofit2_Okhttp3_Protocolexception - Fatal编程技术网

Android ProtocolException:应为';:状态';标题不存在

Android ProtocolException:应为';:状态';标题不存在,android,retrofit,retrofit2,okhttp3,protocolexception,Android,Retrofit,Retrofit2,Okhttp3,Protocolexception,改造网络呼叫失败,工作应用程序中突然出现协议异常。 该应用程序一直工作到昨天,今天所有的网络通话都失败了。这些调用在HTTP中工作正常,但在HTTPS中失败 这是日志 java.net.ProtocolException: Expected ':status' header not present 10-18 14:59:01.103 30746-30746/? W/System.err: at okhttp3.internal.http.Http2xStream.readHttp2He

改造网络呼叫失败,工作应用程序中突然出现协议异常。 该应用程序一直工作到昨天,今天所有的网络通话都失败了。这些调用在HTTP中工作正常,但在HTTPS中失败

这是日志

java.net.ProtocolException: Expected ':status' header not present
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.Http2xStream.readHttp2HeadersList(Http2xStream.java:262)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:145)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at codmob.com.campuswallet.app.ApiClient$1.intercept(ApiClient.java:66)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
10-18 14:59:01.103 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall.access$100(RealCall.java:33)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
10-18 14:59:01.104 30746-30746/? W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
10-18 14:59:01.104 30746-30746/? W/System.err:     at java.lang.Thread.run(Thread.java:761)

今天,我们面临着同样的问题。原因是将服务器上的nginx更新为最新版本(1.13.6)。询问您的后端团队是否未更新服务器上的nginx


nginx changelog-

经过数小时的混乱,终于找到了解决方案。将改型和Okhttp3库更新到最新版本对我起到了作用

compile 'com.squareup.okhttp3:okhttp:3.9.0'

compile 'com.squareup.retrofit2:retrofit:2.3.0'

我使用的是
OkHttp2
(2.7.5),我通过强制客户端使用
htp1.1
协议解决了这个问题

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_1_1)); // <- add this line
OkHttpClient=new-OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_1_1));// 我正在使用okhttp3(okhttp-3.4.1),okhttp3与HTTP_1.1协议不太兼容,需要手动添加。你可以看到

OkHttpClient.Builder=new-OkHttpClient.Builder();
//协议
列表协议=新的ArrayList();
protocols.add(Protocol.HTTP_1_1);
protocols.add(Protocol.HTTP_2);
协议(协议);

在答案中张贴链接页面的相关部分,这样即使页面发生变化,答案仍然有用。更新到最新版本的okhttp3(3.9.0)和改型2(2.3,0)对我来说是个好办法。但我正在使用sucuri,可能的原因是什么?通过使用此修复程序,我的问题仍然存在。如果你的应用程序正在生产中,这不是修复程序-用户在更新之前会继续遇到问题@aradon answer解释了原因,更合适的做法是降级nginx并更新OKTHP。这是什么意思?@Bajranghuda这一行表示您的
OkHttp
客户端在可用时不会尝试使用
http2
协议。您只需将这一行代码放入客户端应用程序源代码中,并将新版本发布到生产环境中即可。好了,我明白你的意思了。但为什么应用程序突然停止工作?昨天它在同一台设备上工作,但今天它只能通过设置Protocol.Http.1.1来工作。为什么会这样?@Bajranghuda可能是您或某人将服务器引擎更新为支持
http2
协议的版本。这是我的理由。@Bajranghuda这是我的想法:
http2
是一种新的协议,而且旧的Android似乎不支持它-所以
OkHttp2
只使用了运行良好的
http1.1
。较新的安卓版本支持
http2
OkHttp2
(它不能很好地处理
http2
)做出决定“让我们使用这个新的
http2
协议,因为它在服务器上可用”-这就是它不工作的原因。您已经解决了这个问题吗?尝试这个链接
OkHttpClient.Builder builder = new OkHttpClient.Builder();
//protocols
List<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(Protocol.HTTP_1_1);
protocols.add(Protocol.HTTP_2);
builder.protocols(protocols);