httpclient post怎么样发送json到服务器

移动开发 码拜 8年前 (2016-05-03) 1009次浏览
与后台交互,需要用json发送到服务器,json已经拿到,怎么样发送呢?httpclient post怎么样发送json到服务器
解决方案

60

JSONObject jsonParam = new JSONObject();  
jsonParam.put("chnl_id", "11");
jsonParam.put("title", bean.getTitle());
StringEntity entity = new StringEntity(jsonParam.toString(),"utf-8");
entity.setContentEncoding("UTF-8");    
entity.setContentType("application/json");    
HttpPost method = new HttpPost(url);  
method.setEntity(entity);    
HttpResponse result = httpClient.execute(method);

可以参考一下这段..
///

20

引用:

谢谢,但是这个不是应该用outputStream的方式,发送到服务器上吗。?

发送http请求,有很多接口可以用的。上面是一种,你说的是另一种。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明httpclient post怎么样发送json到服务器
喜欢 (0)
[1034331897@qq.com]
分享 (0)