初めまして。zenと申します。
行き詰まっていますので質問させて頂きます。
現在Android > PHP > MySQLという流れでPostしてデータ検索・作成するアプリを製作しています。
事前にMySQLに作成したデータは問題なく取得できたのですが、
Androidから送信したマルチバイト文字のみが文字化けしてデータベースに格納されてしまいます。
どうも原因はAndroid(java) > PHPの間にあると思い、
下記URLを参考にしましたが、どうも修正方法がわかりません。
https://groups.google.com/group/android-group-japan/browse_thread/thread/ed1fa5993ddcaf06?hl=ja
ご教授頂けると幸いです。
以下Android側コード------------------------------------------------------
public class Phppost{
private static final String url = "
http://www.hoge.net/post.php";
public String create(int type, String description, String password,
int latitude, int longitude,int rank){
String retText = null;
//-----[クライアント設定]
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
//-----[POST送信するデータを格納]
List<NameValuePair> nameValuePair = new
ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("type",
String.valueOf(type))); //検索or作成
nameValuePair.add(new BasicNameValuePair("description",
description)); //説明
nameValuePair.add(new BasicNameValuePair("password",
password)); //パスワード
nameValuePair.add(new BasicNameValuePair("latitude",
String.valueOf(latitude))); //緯度
nameValuePair.add(new BasicNameValuePair("longitude",
String.valueOf(longitude))); //経度
nameValuePair.add(new BasicNameValuePair("rank",
String.valueOf(rank))); //評価
try{
//-----[POST送信]
httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse response = httpclient.execute(httppost);
ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
response.getEntity().writeTo(byteArrayOutputStream);
//-----[サーバーからの応答を取得]
if(response.getStatusLine().getStatusCode() ==
HttpStatus.SC_OK){
String oriText = byteArrayOutputStream.toString();
//広告の排除処理
//"[[["から"]]]"までの文字列を取り出す
retText = new String(oriText.substring(oriText.indexOf("[[[")
+3, oriText.indexOf("]]]")));
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return retText;
}