Android帖子请求转义字符

时间:2012-04-17 15:03:35

标签: java android http escaping character

如何在字符串中转义字符“ü”。

我的json数据中有这个字符:

{"Name": "Hyüsin"}

当我在我的android中对WebServer执行HttpPost时。它给我一个“错误请求”错误作为回应。

HttpPost代码:

    // uploads the data
public class UploadData extends AsyncTask<String, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(String... url) {

            try {

                HttpPost request = new HttpPost(LogInActivity.SERVICE_URI + url[0]);

                request.setHeader("Content-type", "application/json; charset=utf-8");


                //THIS IS  {"Name": "Hyüsin"}               
                JSONObject jsonTaakkaart = taakkaart.serializeToObj();




                StringEntity entity = new StringEntity(jsonTaakkaart .toString());
                request.setEntity(entity);


                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpResponse response = httpClient.execute(request);


                return true;

            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }

        }
    }

1 个答案:

答案 0 :(得分:4)

使用:

StringEntity entity = new StringEntity(jsonTaakkaart.toString(), "UTF-8");

指定编码为UTF-8。