package asi;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class TestHttpClient { public static void main(String[] args){
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(150000)
.setConnectTimeout(150000)
.setConnectionRequestTimeout(150000)
.build();
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
HttpEntity httpEntity = null;
String responseContent = null; String url=...
String json=...
HttpPost httpPost=new HttpPost(url);
httpPost.addHeader("Content-type","application/json; charset=utf-8");
httpPost.setHeader("Accept", "application/json");
try {
StringEntity stringEntity = new StringEntity(json, "UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
httpPost.setConfig(requestConfig);
response = httpClient.execute(httpPost);
httpEntity = response.getEntity();
responseContent = EntityUtils.toString(httpEntity, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(responseContent);
} }

httpclient发送请求的几种方式的更多相关文章

  1. java web前端发送请求的4种方式

    表单 action, 链接href,js 绑定按钮 ajax绑定标签 <h1>通过表单提交参数</h1> <form action="/day46_v1/Ser ...

  2. C#中Post请求的两种方式发送参数链和Body的

    POST请求 有两种方式 一种是组装key=value这种参数对的方式 一种是直接把一个字符串发送过去 作为body的方式 我们在postman中可以看到 sfdsafd sdfsdfds publi ...

  3. .NetCore HttpClient发送请求的时候为什么自动带上了一个RequestId头部?

    奇怪的问题 最近在公司有个系统需要调用第三方的一个webservice.本来调用一个下很简单的事情,使用HttpClient构造一个SOAP请求发送出去拿到XML解析就是了. 可奇怪的是我们的请求在运 ...

  4. 使用HttpClient发送请求、接收响应

    使用HttpClient发送请求.接收响应很简单,只要如下几步即可. 1.创建HttpClient对象.  CloseableHttpClient httpclient = HttpClients.c ...

  5. 第二节:SSL证书的申请、配置(IIS通用)及跳转Https请求的两种方式

    一. 相关概念介绍 1. SSL证书服务 SSL证书服务由"服务商"联合多家国内外数字证书管理和颁发的权威机构.在xx云平台上直接提供的服务器数字证书.您可以在阿里云.腾讯云等平台 ...

  6. Spring MVC中forward请求转发2种方式(带参数)

    Spring MVC中forward请求转发2种方式(带参数) http://www.51gjie.com/javaweb/956.html  

  7. 解决 SharePoint 2010 拒绝访问爬网内容源错误的小技巧(禁用环回请求的两种方式)

    这里有一条解决在SharePoint 2010搜索爬网时遇到的“拒绝访问错误”的小技巧. 首先要检查默认内容访问帐户是否具有相应的访问权限,或者添加一条相应的爬网规则.如果目标资源库是一个ShareP ...

  8. nginx分发请求的2种方式:1、指明server_name;2、通过location过滤uri来分发请求;

    user nginx; worker_processes 8; # = cpu num; error_log /data/nginx/log/error/error.log warn; # warn, ...

  9. Python 发送 email 的两种方式

    Python发送email的两种方式,分别为使用登录邮件服务器.调用sendmail命令来发送三种方法 Python发送email比较简单,可以通过登录邮件服务来发送,linux下也可以使用调用sen ...

随机推荐

  1. 在vue中使用elementUI饿了么框架使用el-calendar日历组件,实现自定义显示备忘录标注

    饿了么官网给的自定义例子是点击哪个日期在日期后面加个勾 而我们想要的是显示备忘录,像这样↓,日历上直接显示 这时候我们要把template里的代码改一下 <el-calendar> < ...

  2. .NET Core 初次上手Swagger

    安装NuGet 程序包=>Swashbuckle.AspNetCore 在  Startup.ConfigureServices  方法里添加注册生成器 //注册Swagger生成器,定义一个和 ...

  3. P1642 规划 [01分数规划]

    裸题,考虑size完了跑一个树上背包,这题没了. // by Isaunoya #include <bits/stdc++.h> using namespace std; #define ...

  4. 【13】正则化网络激活函数(Batch归一化)

    正则化网络激活函数(Batch归一化): 在神经网络训练中,只是对输入层数据进行归一化处理,却没有在中间层进行归一化处理.要知道,虽然我们对输入数据进行了归一化处理,但是输入数据经过σ(WX+b)σ( ...

  5. Docker学习参考网站

    Docker——从入门到实践 https://www.yuque.com/grasilife/docker 2.阿里源网站:https://cr.console.aliyun.com 3.DaoClo ...

  6. Qt Gui 第五章绘图类

    双缓冲 void Plotter::refreshPixmap() { pixmap = QPixmap(size()); pixmap.fill(, ); QPainter painter(& ...

  7. IDEA 解决Number objects are compared using '==', not 'equals()' 警告

    当代码被工具标黄色高亮时,代表需要优化或重构了 == 是值相等.对于Integer这样的数据类型而言,意义是两个Integer对象的内存地址相等.也就是说如果你有两个不同的Integer的对象, 如果 ...

  8. 03_TypeScript函数

    1.函数的定义 es5定义函数的方法 //函数声明法 function run(){ return 'run'; } //函数表达式 var run = function(){ return 'run ...

  9. 探索drf执行流程之APIView源码分析

    Django REST framework 简介 现在新一代web应用都开始采用前后端分离的方式来进行,淘汰了以前的服务器端渲染的方式.而实现前后端分离是通过Django REST framework ...

  10. liunx 查找locate

    使用 安装 yum install mlocate 更新数据库 updatedb 查找my.cnf文件 locate my.cnf