我为charset使用“UTF-8”以包含土耳其字符。在消息传递部分可以显示土耳其字符,但是,在相同的系统中,用户简要部分不能正确编码土耳其字符。用户简介异步部分代码段:
public class ServerKullaniciDurum extends AsyncTask<String, Void, String> {
String durum;
String query, charset;
public ServerKullaniciDurum(String durum) {
this.durum = durum;
charset = "UTF-8";
String param1 = "id";
String param2 = "status";
try {
query = String.format("param1=%s¶m2=%s", URLEncoder.encode(param1, charset), URLEncoder.encode(param2, charset));
} catch (IOException e) {
e.printStackTrace();
}
}
protected String doInBackground(String... params) {
URLConnection connection = null;
try {
Log.i("tago" , "durum" + durum);
Log.i("tago" , "durum encode " + URLEncoder.encode(durum,charset));
connection = new URL("http://www.ceng.metu.edu.tr/~e1818871/shappy/my_status?id="
+ params[0] + "&status=" + URLEncoder.encode(durum, charset)).openConnection();
} catch (IOException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
OutputStream output;
try {
output = new BufferedOutputStream(connection.getOutputStream());
output.write(query.getBytes(charset));
InputStream inputstream = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return "calaba";
}
}
这是什么原因?我怎么能克服它?