U
U
Unkow2014-06-21 12:27:00
PHP
Unkow, 2014-06-21 12:27:00

How to set POST request encoding on Android?

Actually the question is: There is a REST API, I send values ​​​​to it and they are entered into the database, if through a test tool (well, sending POST, GET with parameters) then everything is ok with Russian letters, if I make a POST request with the same parameters via Android - then the encoding in the database is not clear, instead of Russian characters, question marks.
As I tested - chrome extension - Advanced REST client, through it you can send POST, GET, PUT, etc. with parameters. Through it, everything is perfectly entered with Russian characters. Through Android, everything is crooked, here is the code:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = null;
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(httpPost);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat S, 2014-06-22
@Unkow

httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
...
setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
...
Once I had to convert manually. resulting json
commons.apache.org/proper/commons-lang
StringEscapeUtils.unescapeJava(String str)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question