原代码
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://*******.html");
StringEntity postingString = new StringEntity(json.toJSONString());
post.setEntity(postingString);
post.setHeader("Content-type", "application/json;charset=UTF-8");
HttpResponse response = httpClient.execute(post);
System.out.println(EntityUtils.toString(response.getEntity()));
发送中文一直为乱码。解决方案如下:
StringEntity postingString = new StringEntity(json.toJSONString(),"UTF-8");