有什么方法可以禁用或绕过 OkHttp 上的 checkNameAndValue 异常?

Any way to disable or get around checkNameAndValue exceptions on OkHttp?

我正在尝试使用 OkHttp 进行调用,但出现异常,因为其中一个 header 出现问题。 header 是:

Content-Disposition: attachment; filename="O Último Caçador de Bruxas (2016) 5.1 CH Dublado 1080p.mp4"

我无法控制服务器所以我想知道我是否可以告诉 OkHttp 忽略该错误?

这是完整的例外。

java.lang.IllegalArgumentException: Unexpected char 0xda at 24 in content-disposition value: attachment; filename="O Último Caçador de Bruxas (2016) 5.1 CH Dublado 1080p.mp4" at okhttp3.Headers$Builder.checkNameAndValue(Headers.java:283) at okhttp3.Headers$Builder.add(Headers.java:233) at okhttp3.internal.http.Http2xStream.readHttp2HeadersList(Http2xStream.java:263) at okhttp3.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:149) at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:723) at okhttp3.internal.http.HttpEngine.access0(HttpEngine.java:81) at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:708) at com.facebook.stetho.okhttp3.StethoInterceptor.intercept(StethoInterceptor.java:59) at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:681) at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563) at okhttp3.RealCall.getResponse(RealCall.java:241) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160) at okhttp3.RealCall.execute(RealCall.java:57)

这是 OkHttp 中的一个错误。您可以通过禁用 HTTP/2.

来解决它

http://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#protocols-java.util.List-