httpclient post 发送Json数据
2015-12-28 00:00
633 查看
摘要: 包:httpclient-4.5.1 httpcore-4.4.3
String url = "http://127.0.0.1:8099/login"; String json = "{\"login_name\": \"18800000000\",\"login_password\": \"123456\"}"; @Test public void post() throws ClientProtocolException, IOException{ //创建client CloseableHttpClient httpclient = HttpClients.createDefault(); try { //创建post请求 HttpPost httppost = new HttpPost(url); //json StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httppost.setEntity(entity); System.out.println("executing request " + httppost.getRequestLine()); //执行post请求 CloseableHttpResponse response = httpclient.execute(httppost); try { System.out.println("----------------------------------------"); //状态 System.out.println(response.getStatusLine()); //响应实体 HttpEntity resEntity = response.getEntity(); if (resEntity != null) { System.out.println(EntityUtils.toString(resEntity)); } //关闭HttpEntity流 EntityUtils.consume(resEntity); } finally { response.close(); } } finally { httpclient.close(); } }
相关文章推荐
- XML 与 JSON 优劣对比
- VBA将excel数据表生成JSON文件
- newtonsoft.json解析天气数据出错解决方法
- vbs 解析json jsonp的方法
- Extjs4如何处理后台json数据中日期和时间
- C#实现将类的内容写成JSON格式字符串的方法
- JQuery ajax返回JSON时的处理方式 (三种方式)
- jquery JSON的解析方式示例介绍
- c#版json数据解析示例分享
- ASP JSON类文件的使用方法
- POST与GET方法的区别简要分析
- C#实现对Json字符串处理实例
- C#使用post发送和接收数据的方法
- C#实现Json转Unicode的方法
- PHP响应post请求上传文件的方法
- VB使用XMLHTTP实现Post与Get的方法
- 分享下GET和POST的真正区别
- php采用ajax数据提交post与post常见方法总结
- php解析json数据实例