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?