2

I'm trying to make a call with OkHttp and I'm getting an exception because one of the headers has an issue. The header is:

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

I have no control over the server so I want to know if I can tell OkHttp to ignore that error?

Here is the full exception.

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.access$200(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)

casolorz
  • 8,486
  • 19
  • 93
  • 200

1 Answers1

1

It's a bug in OkHttp. You can workaround it by disabling HTTP/2.

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

Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128
  • Thanks for the reply, I tried that this morning and still got the same exception `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"` – casolorz May 24 '16 at 12:02
  • Just to be clear this is what I did on my quick test ` ArrayList protocols = new ArrayList<>(); protocols.add(Protocol.HTTP_1_1); protocols.add(Protocol.SPDY_3); builder.protocols(protocols);` – casolorz May 24 '16 at 12:30
  • 1
    Had to remove `SPDY_3` as well. Thanks. – casolorz May 24 '16 at 12:44
  • not working to me, i got "java.lang.IllegalArgumentException: Unexpected char 0x306 at 45 in Content-Disposition value: form-data; name="chunkMetadata"; filename="văn bản-5EFD5D71A83F-1.txt.001", seem issue cause by utf-8, tried to using URLEncoder but not working – famfamfam Mar 25 '21 at 06:44