作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序出现问题,当我尝试向我的 apache 服务器发送包含 má mé mí mó mú 等字符的文本时,它发送的字符为 m?。我该如何解决这个问题?
这是我的代码:
public boolean loginstatus(String reporte, String user) {
File file = new File(fileUri.getPath());
try {
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
Log.e("enviando", "archivo "+fileUri.getPath());
Log.e("enviando", "reporte "+reporte);
Log.e("enviando", "usuario "+user);
entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addTextBody("reporte", reporte);
entity.addTextBody("usuarioID",user);
if (file.length() <= 0){
}else{
entity.addPart("archivo", new FileBody(file));
}
final HttpEntity yourEntity = entity.build();
httppost.setEntity(yourEntity);
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
最佳答案
首先,这里的问题是你的编码。数据库的表未编码为使用 UTF-8,或者您发送的字符串不是。
表格问题:
您可以在数据库表上使用CHARACTER SET utf8
。
字符串问题:解决这个问题的优雅方法是使用
StringEntity实体 = new StringEntity(Yourtext, "UTF-8");
另一种方法是使用 String 的 getBytes("UTF-8")
函数并使用 DataOutputStream
关于java - Android 如何将带有重音符号的文本发送到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20005437/
我是一名优秀的程序员,十分优秀!