http-request
http-request copied to clipboard
non latin characters
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));
It should default to UTF-8 already, can you include an example snippet where it isn't encoding things correctly?
Thanks.
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
Are you using the StringEntity
class from Apache HttpComponents?
I use simple String. How can i use StringEntity in your library?
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?
I'll try it tommorow, thank you for answering.
not working((
Can you include an example code snippet that is failing for you?
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 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 , 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);
}