Java android将utf8内容发送到servlet
我使用Android将英语和阿拉伯语内容发送到Servlet,但数据会随文件一起发送到服务器。如何解决?以下是我在Android中的代码:Java android将utf8内容发送到servlet,java,android,hibernate,servlets,web,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
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代码
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();
}
有什么建议吗?使用这些方法
HttpPost httpPost = new HttpPost(method_url);
StringEntity postEntity = new StringEntity(HTTP.UTF_8);
httpPost.setEntity(postEntity)
或
使用这些方法
HttpPost httpPost = new HttpPost(method_url);
StringEntity postEntity = new StringEntity(HTTP.UTF_8);
httpPost.setEntity(postEntity)
或
您是否尝试过使用UTF8格式创建StringEntity,我在代码中的意思是:StringEntity se=new StringEntity(gsonString,“UTF-8”);为什么要将字符编码设置为
request.setCharacterEncoding(“UTF-16”)代码>尝试UTF-8
关于StringEntity se=新的StringEntity(gsonString,“UTF-8”);服务器遇到的相同问题?????关于UTF-16,我之前尝试过插入数据库中的UTF-8????然后我使用了utf-16 it Works。您是否尝试过使用UTF8格式创建StringEntity,我的意思是在代码中类似这样的内容:StringEntity se=new StringEntity(gsonString,“utf-8”);为什么要将字符编码设置为request.setCharacterEncoding(“UTF-16”)代码>尝试UTF-8
关于StringEntity se=新的StringEntity(gsonString,“UTF-8”);服务器遇到的相同问题?????关于UTF-16,我之前尝试过插入数据库中的UTF-8????然后我使用utf-16 it worksStringEntity postEntity=newStringEntity(HTTP.utf_8);httpPost.setEntity(postEntity);如何将数据放入此stringEntity???我不知道它是否正确我不知道如何将数据写入此entityStringEntity postEntity=new stringEntity(HTTP.UTF_8);httpPost.setEntity(postEntity);如何将数据放入这个stringEntity???我不知道它是否正确我不知道如何将数据写入这个实体
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);