zoukankan      html  css  js  c++  java
  • 接口自动化测试HttpClient-基础篇2-Post请求

    HttpClient Post请求及响应处理,大致和Get请求相同

    //创建HttpClient对象

      CloseableHttpClient httpclient = HttpClients.createDefault();

    // 创建带请求地址的HttpPost对象

      HttpPost httpPost = new HttpPost("http://***");

    //设置HttpPost参数

      StringEntity entity = new StringEntity("param","utf-8");

      entity.setContentType("application/json");

      httpPost.setEntity(entity);

    ================

    //执行获取post请求的响应

      CloseableHttpResponse response = httpclient.execute(httpPost);

    // 获取响应实体

      HttpEntity entity = response.getEntity();

    // 获取响应内容

      EntityUtils.toString(entity, "UTF-8"));

    //释放资源

      EntityUtils.consume(entity);

    实例:demo

  • 相关阅读:
    struts.xml
    web.xml
    jdbc.properties
    apache+tomcat的集群--Session复制配置
    mysql 定时触发器
    mysql 查看存储过程
    Quatz 定时任务
    Apache Httpd常用命令
    Mac安装nginx
    dubbo ReferenceConfig源码分析
  • 原文地址:https://www.cnblogs.com/cocowang68/p/9105479.html
Copyright © 2011-2022 走看看