android将utf8内容发送给servlet

yeh*_*ria 1 java android hibernate servlets web

我正在使用Android将英语和阿拉伯语内容发送到Servlet,但数据会发送到服务器.怎么解决?这是Android中的代码:

StringEntity se = new StringEntity(gsonString);
se.setContentType("text/json;charset=UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json;charset=UTF-8"));
HttpPost httpRequest = new HttpPost(methodURL);
httpRequest.setEntity(se);
HttpResponse response = httpClient.execute(httpRequest,localContext);
Run Code Online (Sandbox Code Playgroud)

Servlet代码

request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
    String line = in.readLine();
    String gsonString = line;
    while (line != null) {
        gsonString += line;
        line = in.readLine();
    }
Run Code Online (Sandbox Code Playgroud)

有什么建议 ?

yeh*_*ria 5

HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();

Gson gson = new Gson();
        String gsonString = gson.toJson(currentCustomer);
        Log.v("gson", gsonString);

        StringEntity se = new StringEntity(gson.toJson(currentCustomer),
                "UTF-8");
HttpPost httpRequest = new HttpPost(methodURL);
        httpRequest.setHeader("customerRegisrationData", gsonString);
        httpRequest.setEntity(se);

        HttpResponse response = httpClient.execute(httpRequest,
                localContext);
Run Code Online (Sandbox Code Playgroud)