android send utf8 content to servlet

I'm using Android to send English and Arabic content to Servlet but the data goes to the server with. How to solve it ? here is my code in 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);

Servlet code

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

any suggestions ?

Answers


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

Use these methods

HttpPost httpPost = new HttpPost(method_url);

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

OR

httpPost.setEntity(new UrlEncodedFormEntity(postData));

Need Your Help

Sending a password to Gmail from my Android javamail app

android security encryption passwords gmail

I'm writing an Android email client app, based on the Javamail API. I can log into GMail accounts from it, but I want to make sure that the login process is actually secure.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.