HttpPost post=new HttpPost(url);
StringEntity content=new StringEntity(data, Charset.forName("utf-8"));// 设置编码
content.setContentType("application/json; charset=UTF-8");
content.setContentEncoding("utf-8");
post.setEntity(content);
第二种:
httpPost.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));//在设置请求数据的时候,指定编码
http://blog.youkuaiyun.com/shuaipu813/article/details/52353023
本文提供了两种使用 Java 发送 HTTP Post 请求的方法。第一种方法通过 StringEntity 设置 JSON 格式的请求体;第二种方法则利用 UrlEncodedFormEntity 处理表单格式的数据。
6352

被折叠的 条评论
为什么被折叠?



