问题描述
我看到这个问题问了很多遍,但是我的情况不同。请不要将其标记为重复。
以下是我的改造客户。当我们使用apk时,效果很好。但是,一旦将其转换为citrix / secure hub的MDX,我们将面临流错误的终结。
我也尝试过凌空抽射,但出现了同样的错误。如您所见,我已经尝试了所有拦截器以及所有的改装。
已经尝试过以下拦截器。
- addHeader(“ Connection”,“ close”)
- retryOnConnectionFailure(true)
所以我的问题是到底发生了什么?为什么它在apk上而不在MDX上起作用。
public static Retrofit getClient() {
//Basic Auth
String authToken = null;
if (!TextUtils.isEmpty(AppConfig.username) &&
!TextUtils.isEmpty(AppConfig.password)) {
authToken = Credentials.basic((String) AppConfig.username,(String) AppConfig.password);
}
//Create a new Interceptor.
final String finalAuthToken = authToken;
Interceptor headerAuthorizationInterceptor = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Request request = chain.request();
Headers headers = request.headers().newBuilder()
// .add("Authorization",finalAuthToken)
.add("Connection","close").build();
request = request.newBuilder().headers(headers).build();
return chain.proceed(request);
}
};
//TO be added in milliseconds
List < Protocol > protos = new ArrayList < > ();
protos.add(Protocol.HTTP_2);
protos.add(Protocol.HTTP_1_1);
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.protocols(protos)
.retryOnConnectionFailure(true) //FirsT TRY : Added this line after getting Unexpected end of stream error.
.connectTimeout(180,TimeUnit.SECONDS)
.readTimeout(180,TimeUnit.SECONDS)
.writeTimeout(180,TimeUnit.SECONDS)
//.addInterceptor(new GzipRequestInterceptor())
// THIRD TRY : Added this new interceptor for end of stream error
/*.addInterceptor(new Interceptor() {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.addHeader("Connection","close")
.addHeader("transfer-encoding","chunked")
//.addHeader("Accept-Encoding","gzip")
.build();
return chain.proceed(request);
}
})*/
//.addInterceptor(headerAuthorizationInterceptor) // SECOND TRY : Added this line after getting Unexpected end of stream error. fot connection close
//ABOVE LINE is Next try would be adding this line as
// this headerInterceptor we have added .add("Connection","close")
// may be we need to remove the authorization from that headerInterceptor
.build();
return new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.baseUrl(AppConfig.mainURLDev3forRetrofit2)
.build(); }
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)