HttpClient常用方法总结
2024-09-05 12:56:28
1、HttpPost发送表单请求
String url = "";
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("username", "root"));
params.add(new BasicNameValuePair("password", "123456"));
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(params, "utf-8");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
httpPost.setEntity(uefEntity);
2、HttpPost发送json参数请求
String url = "";
String json = ""; // 请求参数,json格式
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(json, "UTF-8");
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(entity);
3、HttpPost发送xml参数请求
String url = "";
String xml = ""; // 请求参数,xml格式
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(xml, "UTF-8");
httpPost.setHeader("Content-Type", "text/xml");
httpPost.setEntity(entity);
最新文章
- 解释器模式(Interpreter Pattern)
- collection集合框架
- MMORPG大型游戏设计与开发(客户端架构 part1 of vegine)
- flexslider.js和waypoints.js一起用时的巨坑
- char与TCHAR相互转化
- 菜刀轻松砍杀安全狗 asp一句话中转脚本
- win7下以兼容模式安装oracle10g
- Activity Threa创建Window和View分析
- python ATM购物程序
- JavaScript 内存
- 关于tomcat部署应用的三种方式
- TSL1401线性CCD TM32F103开发平台移植源代码
- 最近面试被问到一个问题,AtomicInteger如何保证线程安全?
- External Snapshot management
- spring-boot整合mybatis(web mysql logback配置)
- C#串口SerialPort常用属性方法
- CSS快速入门-属性和伪类
- 【基础】java类的各种成员初始化顺序
- HDU 1402
- 宿主机ssh免密登录docker容器