1

我正在使用 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);

小服务程序代码

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();
    }

有什么建议么 ?

4

2 回答 2

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);
于 2013-04-24T23:36:11.830 回答
1

使用这些方法

HttpPost httpPost = new HttpPost(method_url);

StringEntity postEntity = new StringEntity(HTTP.UTF_8);
httpPost.setEntity(postEntity)

或者

httpPost.setEntity(new UrlEncodedFormEntity(postData));
于 2013-01-23T13:07:21.417 回答