I have an Android app that allows you to publish your name on a website, although I configure it by sending an HTTP request to the website. The problem is that 90% of our customers are Swedish, and the POST request seems to interrupt everything after the special character in the string, including the special character itself.
So, the Swedish last name "Börjesson" becomes "B".
my POST request code:
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;
}
So, any tips on what I'm doing wrong?
Thanks in advance!
source
share