httpClient发送post请求,传递json字符串
来源:互联网 发布:易打单软件 编辑:程序博客网 时间:2024/05/20 08:45
传文件的已经写了,传json字符串的稍微简单点。
public static String doPostJson(String url, String json,Log logger) { // 创建Httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; String resultString = ""; try { // 创建Http Post请求 HttpPost httpPost = new HttpPost(url); // 创建请求内容 StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httpPost.setEntity(entity); // 执行http请求 response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); } catch (Exception e) { logger.error("端口数据获取Bug:"+e); e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { e.printStackTrace(); } } return resultString; }
阅读全文
0 0
- httpClient发送post请求,传递json字符串
- httpClient 发送 post请求 json数据
- HttpClient post请求 发送Json数据
- HttpClient构造post请求,发送一串字符串
- Httpclient发送POST请求
- httpClient发送post请求
- HttpClient发送post请求
- httpclient发送post请求
- HttpClient 发送 POST 请求
- httpclient发送post请求
- httpClient发送post请求
- httpclient 发送post请求
- Android发送Post请求获取Json字符串
- java httpclient POST和GET请求 发送JSON
- 用HttpClient发送post请求
- 使用HttpClient发送POST请求
- 使用httpclient发送post请求
- httpClient post发送json数据
- 剑指offer-操作给定的二叉树,将其变换为源二叉树的镜像
- CentOS-6.5安装与配置Tomcat-7
- constexpr-not-compiling-in-vc2013
- 遮挡层代码
- java面向对象的理解
- httpClient发送post请求,传递json字符串
- paly()方法和pause()方法
- ArrayBlockingQueue 和LinkedBlockingQueue
- shrio验证cookie有效性
- tomcat优化
- 【0020】html5文件初始模板
- 代码更改Unity设置中的ICON
- python的UDP中,server自己给自己发信息,不能发送到client的问题
- 在eclipse中创建一个Maven Web项目