Android如何使用重音发送文本到PHP

时间:2013-11-15 16:10:17

标签: java android diacritics

我的应用程序出现问题,当我尝试将文本发送到我的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;

        }

1 个答案:

答案 0 :(得分:1)

首先,这里的问题是你的编码。 数据库的表未编码为使用UTF-8或您发送的字符串不是。

表格问题:

您可以在数据库表上使用CHARACTER SET utf8

字符串问题: 解决它的优雅方法是使用

StringEntity entity = new StringEntity(Yourtext, "UTF-8");

另一种方法是使用String的 getBytes("UTF-8") 函数并使用DataOutputStream