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);

最新文章

  1. 解释器模式(Interpreter Pattern)
  2. collection集合框架
  3. MMORPG大型游戏设计与开发(客户端架构 part1 of vegine)
  4. flexslider.js和waypoints.js一起用时的巨坑
  5. char与TCHAR相互转化
  6. 菜刀轻松砍杀安全狗 asp一句话中转脚本
  7. win7下以兼容模式安装oracle10g
  8. Activity Threa创建Window和View分析
  9. python ATM购物程序
  10. JavaScript 内存
  11. 关于tomcat部署应用的三种方式
  12. TSL1401线性CCD TM32F103开发平台移植源代码
  13. 最近面试被问到一个问题,AtomicInteger如何保证线程安全?
  14. External Snapshot management
  15. spring-boot整合mybatis(web mysql logback配置)
  16. C#串口SerialPort常用属性方法
  17. CSS快速入门-属性和伪类
  18. 【基础】java类的各种成员初始化顺序
  19. HDU 1402
  20. 宿主机ssh免密登录docker容器

热门文章

  1. MessagePack Java Jackson 在不关闭输入流(input stream)的情况下反序列化多变量
  2. websocket 连接测试端口服务是否正常代码
  3. TensorFlow使用记录 (六): 优化器
  4. Git与Repo 的使用
  5. &lt;% 拼写页面
  6. python数据可视化示例柱状图
  7. js如何获取鼠标位置
  8. linux目录简介说明
  9. HttpServletRequest中getRemoteUser和getUserPrincipal方法
  10. vue类似tab切换的效果,显示和隐藏的判断。