http-request icon indicating copy to clipboard operation
http-request copied to clipboard

non latin characters

Open iplatonov opened this issue 11 years ago • 11 comments

How can i send POST request with non latin characters? You need to implement somethig like this: request.part(name , new StringEntity(body, HTTP.UTF_8));

iplatonov avatar Apr 24 '13 16:04 iplatonov

It should default to UTF-8 already, can you include an example snippet where it isn't encoding things correctly?

Thanks.

kevinsawicki avatar Apr 24 '13 16:04 kevinsawicki

I'm using method request.part(name , new StringEntity(name, body); where body is String which contains cyrilic characters But server receive incorrect data whith garbage symbols

iplatonov avatar Apr 24 '13 17:04 iplatonov

Are you using the StringEntity class from Apache HttpComponents?

kevinsawicki avatar Apr 24 '13 17:04 kevinsawicki

I use simple String. How can i use StringEntity in your library?

iplatonov avatar Apr 24 '13 17:04 iplatonov

Oh okay, your previous comment was:

I'm using method request.part(name , new StringEntity(name, body);

Which let me to believe you were already trying to use StringEntity.

So you are calling request.part(name, body); where body is a String with cyrillic characters and it isn't sending it correctly to the server?

Have you tried calling request.part(name, null, 'UTF-8', body) instead?

kevinsawicki avatar Apr 24 '13 17:04 kevinsawicki

I'll try it tommorow, thank you for answering.

iplatonov avatar Apr 24 '13 18:04 iplatonov

not working((

iplatonov avatar Apr 26 '13 07:04 iplatonov

Can you include an example code snippet that is failing for you?

kevinsawicki avatar Apr 26 '13 15:04 kevinsawicki

I found it. I have to write content type header for each part of multipart data: request.part(name ,null, "application/x-www-form-urlencoded; charset=UTF-8" , value); maybe it will be useful for somebody.

iplatonov avatar Apr 29 '13 11:04 iplatonov

@iplatonov I would like to add this as a first-class method to the HttpRequest class API.

Can you confirm if calling request.part(name ,null, "text/plain; charset=UTF-8" , value); also works for your case?

kevinsawicki avatar Apr 30 '13 16:04 kevinsawicki

@kevinsawicki , I can confirm that it works (request.part(name ,null, "text/plain; charset=UTF-8" , value);). I agree that adding first class support for this would be nice. Something like the following two methods.

public HttpRequest part(final String name, final String value, final String charset) throws HttpRequestException {
    charset = getValidCharset(charset);
    return part(name, null, "text/plain; charset=" + charset, value);
}

public HttpRequest part(final String name, final String value) throws HttpRequestException {
    return part(name, value, CHARSET_UTF8);
}

vincentjames501 avatar Mar 30 '15 17:03 vincentjames501