You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Hari Iyer <iy...@hotmail.com> on 2021/01/21 12:20:55 UTC
Multipart request with non-ascii filename
Hi,
I have filenames with non-ascii characters and this is the code that enables me to encode it in my multipart request:
MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).setLaxMode();
While this generates the content disposition (for filename Mädchen) correctly as:
Content-Disposition: form-data; name="M[0xc3][0xa4]dchen.pdf"; filename="M[0xc3][0xa4]dchen.pdf"
It also generates content type with a charset parameter like so:
Content-Type: multipart/form-data; boundary=eUBOAfgS-JvSxb2ok4HhwTdwyKWzloz27CnQ0; charset=UTF-8
This request fails with IIS as noted by many others (61384 – Adding charset to multipart/form-data content type irritates IIS (apache.org)<https://bz.apache.org/bugzilla/show_bug.cgi?id=61384>). How do I get around this? Removing the charset prevents the encoding of the filename, adding it breaks IIS. I am using httpclient 4.5.11.
Thanks,
Hari.
Re: Multipart request with non-ascii filename
Posted by Michael Osipov <mi...@apache.org>.
Am 2021-01-21 um 13:20 schrieb Hari Iyer:
> Hi,
> I have filenames with non-ascii characters and this is the code that enables me to encode it in my multipart request:
> MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).setLaxMode();
> While this generates the content disposition (for filename Mädchen) correctly as:
> Content-Disposition: form-data; name="M[0xc3][0xa4]dchen.pdf"; filename="M[0xc3][0xa4]dchen.pdf"
> It also generates content type with a charset parameter like so:
> Content-Type: multipart/form-data; boundary=eUBOAfgS-JvSxb2ok4HhwTdwyKWzloz27CnQ0; charset=UTF-8
> This request fails with IIS as noted by many others (61384 – Adding charset to multipart/form-data content type irritates IIS (apache.org)<https://bz.apache.org/bugzilla/show_bug.cgi?id=61384>). How do I get around this? Removing the charset prevents the encoding of the filename, adding it breaks IIS. I am using httpclient 4.5.11.
> Thanks,
> Hari.
Please read:
* https://tools.ietf.org/html/rfc6266
* https://stackoverflow.com/a/30446122/696632
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Multipart request with non-ascii filename
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2021-01-21 at 12:20 +0000, Hari Iyer wrote:
> Hi,
> I have filenames with non-ascii characters and this is the code that
> enables me to encode it in my multipart request:
> MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).se
> tLaxMode();
> While this generates the content disposition (for filename Mädchen)
> correctly as:
> Content-Disposition: form-data; name="M[0xc3][0xa4]dchen.pdf";
> filename="M[0xc3][0xa4]dchen.pdf"
> It also generates content type with a charset parameter like so:
> Content-Type: multipart/form-data; boundary=eUBOAfgS-
> JvSxb2ok4HhwTdwyKWzloz27CnQ0; charset=UTF-8
> This request fails with IIS as noted by many others (61384 – Adding
> charset to multipart/form-data content type irritates IIS
> (apache.org)<https://bz.apache.org/bugzilla/show_bug.cgi?id=61384>;).
> How do I get around this? Removing the charset prevents the encoding
> of the filename, adding it breaks IIS. I am using httpclient 4.5.11.
> Thanks,
> Hari.
>
>
Hari
This is a bug in IIS and it should be fixed in IIS.
One can suppress the charset parameter in Content-Type header like that
but then one cannot have non-ascii characters in body part headers.
```
HttpEntity httpEntity = MultipartEntityBuilder.create()
.setContentType(ContentType.create("multipart/form-data", (Charset) null))
.build();
System.out.println(httpEntity.getContentType());
```
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org