特殊字符在android手机的POST请求中消失

特殊字符在android手机的POST请求中消失,android,post,special-characters,http-post,Android,Post,Special Characters,Http Post,我已经建立了一个android应用程序,让你在网站上发布你的名字,尽管我的表单会向网站发送http post请求。问题是90%的av my客户是瑞典人,POST请求似乎在字符串中的一个特殊字符后删除了所有内容,包括特殊字符本身 所以瑞典人的姓氏“Börjesson”变成了“B” 我的邮政编码: public static String execRequest(String url, Map<String, String> params) { try { Def

我已经建立了一个android应用程序,让你在网站上发布你的名字,尽管我的表单会向网站发送http post请求。问题是90%的av my客户是瑞典人,POST请求似乎在字符串中的一个特殊字符后删除了所有内容,包括特殊字符本身

所以瑞典人的姓氏“Börjesson”变成了“B”

我的邮政编码:

public static String execRequest(String url, Map<String, String> params)
{
    try {
        DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
        HttpPost httpPost = null;
        HttpGet httpGet = null;
        if(params == null || params.size() == 0) {
            httpGet = new HttpGet(url);
            httpGet.setHeader("Accept-Encoding", "UTF-8");
        }
        else {
            httpPost = new HttpPost(url);
            httpPost.setHeader("Accept-Encoding", "UTF-8");
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            for(String key: params.keySet()) {
                nameValuePairs.add(new BasicNameValuePair(key, params.get(key)));
            }
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        }
        HttpResponse httpResponse = (HttpResponse)defaultHttpClient.execute(httpPost == null ? httpGet : httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        if(null != httpEntity) {
            InputStream inputStream = httpEntity.getContent();
            Header contentEncoding = httpResponse.getFirstHeader("Content-Encoding");
            if(contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("UTF-8")) {
                inputStream = new GZIPInputStream(inputStream);
            }
            String responseString = convertStreamToString(inputStream);
            inputStream.close();
                return responseString;
        }
    }
    catch(Throwable t) {
        t.printStackTrace();
    }
    return null;
}
publicstaticstringexecrequest(字符串url、映射参数)
{
试一试{
DefaultHttpClient DefaultHttpClient=新的DefaultHttpClient();
HttpPost HttpPost=null;
HttpGet-HttpGet=null;
if(params==null | | params.size()==0){
httpGet=新的httpGet(url);
setHeader(“接受编码”、“UTF-8”);
}
否则{
httpPost=新的httpPost(url);
httpPost.setHeader(“接受编码”、“UTF-8”);
List nameValuePairs=新的ArrayList();
for(字符串键:params.keySet()){
添加(新的BasicNameValuePair(key,params.get(key));
}
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
}
HttpResponse HttpResponse=(HttpResponse)defaultHttpClient.execute(httpPost==null?httpGet:httpPost);
HttpEntity HttpEntity=httpResponse.getEntity();
if(null!=httpEntity){
InputStream InputStream=httpEntity.getContent();
Header contentEncoding=httpResponse.getFirstHeader(“内容编码”);
if(contentEncoding!=null&&contentEncoding.getValue().equalsIgnoreCase(“UTF-8”)){
inputStream=新的GZIPInputStream(inputStream);
}
字符串响应字符串=convertStreamToString(inputStream);
inputStream.close();
回报率;
}
}
捕获(可丢弃的t){
t、 printStackTrace();
}
返回null;
}
那么,有没有关于我做错了什么的提示


提前谢谢

使用
httpPost.setEntity(新的UrlEncodedFormEntity(nameValuePairs,“utf-8”)

您是否尝试过
httpPost.setEntity(新的UrlEncodedFormEntity(nameValuePairs),“utf-8”)我找不到任何具有该参数的函数…该死的,我不好的不是setEntity bat UrlEncodedXXX构造函数
httpPost.setEntity(新的UrlEncodedFormEntity(nameValuePairs,“utf-8”)成功了!:D非常感谢你!将其作为答案发布:)