android http post请求,设置utf-8编码,服务端还是出现中文乱码 解决

来源:互联网 发布:淘宝暴利产品日入上万 编辑:程序博客网 时间:2024/05/12 21:17

 HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("info", "测试")); try {     UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(params, HTTP.UTF_8);     post.setEntity(uefEntity); } catch (UnsupportedEncodingException e) {     Log.e("test", "test"); } HttpResponse response = null; try {     response = httpClient.execute(post); } catch (Exception e) {    …… } if (response.getStatusLine().getStatusCode() == 200) {     …… }
服务端接收到后显示为
解决方法:
HttpPost post = new HttpPost(url);post.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
0 0