Question

I want to send a POST request from android to a PHP application in utf-8 with the below code:

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(Site.SQL_QUERY, "just a test 東京"));

UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(params);
urlEncodedFormEntity.setContentEncoding(HTTP.UTF_8);
httppost.setEntity(urlEncodedFormEntity);

HttpResponse response = httpclient.execute(httppost);
BufferedReader reader = new BufferedReader(new inputStreamReader(response.getEntity().getContent(), HTTP.UTF_8));
String result = reader.readLine();

I set encoding to UTF-8, but Japanese characters contained in the string are not displayed normally.

Here is my PHP code(cakePHP). I just dump parameter.

function sqlQuery(){
   var_dump($this->params['form']['sql_query']);exit;
}

It will display something like "just a test □□"

I have also tried with

mb_convert_encoding ($this->params['form']['sql_query'],"UTF-8")

But problem persists...

Someone can help me ? Thank you

Was it helpful?

Solution

This has been the problem Sending UTF-8 data from Android. Your code would work fine except that you will have to encode your String to Base64 . At Server PHP you just decode Base64 String back. It worked for me. I can share if you need the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top