nanshangzhongdouren
金陵种豆人
采纳率0%
2016-12-06 07:07 阅读 1.2k

httpClient发送json的小程序

5

用spring的组件包HttpClient写一个关于发送json的小程序。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_23039605 小与哥 2016-12-06 07:14
        CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("http://localhost:8080/ydgos/other/updateLogistic.jspx");
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    
            String json = "{\\'name\\':\\'tom\\'}";
            formparams.add(new BasicNameValuePair("json", json));
    
            org.apache.http.client.entity.UrlEncodedFormEntity uefEntity = new org.apache.http.client.entity.UrlEncodedFormEntity(
                    formparams, "utf-8");
    
            httpPost.setEntity(uefEntity);
    
            HttpResponse response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            System.out.println(EntityUtils.toString(entity));
    
    点赞 评论 复制链接分享

相关推荐