2

我看到这个问题问了很多次,但我的情况不同。请不要将其标记为重复。

以下是我的改造客户。当我们使用 apk 时,效果很好。但是,一旦我们将其转换为用于 citrix/secure hub 的 MDX,我们就会面临流错误的结束。

我也用凌空尝试过这个,但我得到了同样的错误。正如你所看到的,我已经尝试了所有的拦截器和所有的改装。

已经尝试过以下拦截器。

  1. addHeader("连接", "关闭")
  2. 重试连接失败(真)

所以我的问题是到底发生了什么?为什么它在 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();  }
4

0 回答 0