cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Character encoding problem in windows when using --data-binary and special characters like 'Ñ'

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 2 Feb 2012 11:10:23 -0800

On Thu, Feb 02, 2012 at 12:54:58PM +0100, Ricardo Vila wrote:
> curl.exe -i -u :'some_token' -H "Accept: application/x-yaml" -H
> "Content-type: text/plain" http://ourserver.com/api/nt/ --data-binary
> @file.properties -X POST
>
> This works fine running curl form linux and windows. But in windows
> appears one problem when in the properties file, appears something
> like this:
>
> documento.productor.centro.nombre=XESTION A CORUÑA, S.A.
>
> The Ñ character is encoded (in windows clients) in a way that our
> server cannot handle it and the rest of the line is trunked. So the
> value on our server for this example is 'XESTION A CORU'
>
> We have tried many things like:
>
> - Use --data-urlencode option (with and without changing content-type)
> - Use --data option
> - Use --data-urlencode with -crlf
> - May combination of the above options
>
> I know that de manual page says ' The contents of the file must
> already be URL-encoded.' but i wonder if i can let curl command manage
> this.
> ¿I'm missing something? ¿Any idea?

curl is undoubtedly sending the file to the remote server exactly as
requested. If so, then the problem won't be solved by adding a curl option
but rather by converting the file into the format that the server
expects before it is sent. The iconv program can be used to convert
between character sets. You'll have to figure out on your own what set
the server expects so that you can convert the file properly.

There is one potential solution that does involve adding a curl option.
If the server is smart enough to convert between character sets itself,
then changing the Content-type: header to something like this:

-H "Content-type: text/plain; charset=utf-8"

where the charset= parameter describes the actual character set used by
file.properties, may allow the server to interpret the contents
correctly and convert it into the format required on the server without
touching the contents of the original file.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-02-02