2011-09-09 8 views
5

ウェブサイトにhttp POST要求を送信するフォームがありますが、あなたの名前をウェブサイトに投稿できるAndroidアプリを作成しました。問題は、私の顧客がスウェーデン語で90%以上で、POST要求が特殊文字そのものを含む文字列内の特殊文字の後にすべてのものを切り刻むように見えることです。アンドロイド携帯電話からのPOSTリクエストで特殊文字が消える

スウェーデンの姓「Börjesson」は「B」になります。

私のPOSTリクエストコード:

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

だから、私が間違ってやっているの任意のヒント?

ありがとうございます!

+1

あなたは 'httpPost.setEntity(新しいUrlEncodedFormEntity(nameValuePairs)、 "UTF-8")を試したんでした;' – Selvin

+0

私はそのパラメータを持つすべての機能を見つけることができません... – Mockarutan

+1

は私の悪いいまいましいです(UrlEncodedFormEntity(nameValuePairs、 "utf-8")); – Selvin

答えて

6

使用httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));

+0

コミュニティwikiとしての回答を投稿してください。同意してください。 – Yury

関連する問題