One part of my application executes a query (via php) in the mysql database. I use UTF-8 in the database because I have letters like é à ê that should appear. I read this problem because it seemed almost the same.
HttpClient task for Android UTF-8
However, when I implement the code, it replaces each return value with é as null.
This is my code.
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
params.setBooleanParameter("http.protocol.expect-continue", false);
HttpClient httpclient = new DefaultHttpClient(params);
HttpPost httppost = new HttpPost("http://www.example.com/example.php");
httppost.setEntity(new UrlEncodedFormEntity(query));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String jsonText = EntityUtils.toString(entity, HTTP.UTF_8);
Toast.makeText(StoresInfo.this, jsonText, Toast.LENGTH_LONG).show();
is = entity.getContent();
So, in the jsonText line, it replaces the return values with "è" in it with a null value.
Last line = entity.getConent (); I added this because I usually use the input stream to read it, but that doesn't work either.
Does anyone have an idea?
This is my php code
<?php
mysql_select_db("database");
$q=mysql_query($_REQUEST['query']);
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
source
share