0

I send a request from a java code to php server then on server side I just echo what has received as response.
So in theory I will receive what I send. but I have problem on sending UTF-8 contents, when I send arabic characters I receive unexpected characters.
My java request code:

HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
            TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);

String requestString = "سلام";

StringEntity entity = new StringEntity(requestString, "UTF-8");
entity.setContentType("application/json");
entity.setContentEncoding("UTF-8");

HttpPost httpPost = new HttpPost(uri);
httpPost.setEntity(entity);
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
httpPost.setHeader("Accept-Charset", "utf-8");

ResponseHandler<String> responseHandler = new BasicResponseHandler();
HttpClient httpClient = new DefaultHttpClient(httpParams);
String responseString=null;
try
{
    responseString = httpClient.execute(httpPost, responseHandler);
}
catch (IOException e)
{  e.printStackTrace(); }

My code on server side:

<?php
    echo file_get_contents('php://input');
?>

In this test I send string "سلام" but in response I receive "Ø³ÙØ§Ù".
I also tried to solve the problem with changing charset with iconv(...) method on php but I failed.
I even don't know the problem is in client or server. Has anybody a help idea?

Aliaaa
  • 1,590
  • 2
  • 16
  • 37
  • Possible duplicate: [file_get_contents() Breaks Up UTF-8 Characters](http://stackoverflow.com/questions/2236668/file-get-contents-breaks-up-utf-8-characters) – BackSlash Jul 25 '13 at 11:05

1 Answers1

0

Answering to my own question:
In my case the problem was in server side. I changed the header of response of server and the problem solved:

header('Content-Type:application/json; charset=utf-8');

Aliaaa
  • 1,590
  • 2
  • 16
  • 37