话不多说,直接上代码:

package com.nuanshui.frms.test.utils.http;

import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse; import java.net.URL; import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.useRelaxedHTTPSValidation; public class RequestUtil {
public static Response sendpostWithHttp(String surl, String str) throws Exception{
String msg=null;
URL url = new URL(surl);
Response response = given().log().all().
header("accept", "application/json").
contentType("application/json").
body(str).
then().
when().
post(url);
response.getBody().prettyPrint(); return response;
}
public static ValidatableResponse sendgetWithHttp(String surl, String str) throws Exception{
URL url = new URL(surl);
ValidatableResponse response = given()
.log().all()
.queryParam(str)
.when()
.get(surl)
.then()
.log().all();
return response;
}
public static Response sendpostWithHttps(String surl, String str) throws Exception{
URL url = new URL(surl);
useRelaxedHTTPSValidation();
Response response = given().log().all().
header("accept", "application/json").
contentType("application/json").
body(str).
then().
statusCode(200).
when().
post(url);
response.getBody().prettyPrint();
return response;
}
public static ValidatableResponse sendgetWithHttps(String surl, String str) throws Exception{
URL url = new URL(surl);
useRelaxedHTTPSValidation();
ValidatableResponse response = given()
.log().all()
.queryParam(str)
.when()
.get(surl)
.then()
.log().all()
.statusCode(200);
return response;
}
}

以上就是对http/https中的get和post进行请求的接口封装,是不是比httpclient的封装实现起来更简洁易懂呢?一起来学习restassurd把~

利用restassured实现http/https接口请求的更多相关文章

  1. java实现https,https接口请求

    /**********************https 接口'*******************/ /** * 安全证书管理器 */public class MyX509TrustManager ...

  2. 利用 Bean Validation 来简化接口请求参数校验

    团队新来了个校招实习生静静,相互交流后发现竟然是我母校同实验室的小学妹,小学妹很热情地认下了我这个失散多年的大湿哥,后来... 小学妹:大湿哥,咱们项目里的 Controller 怎么都看不到参数校验 ...

  3. 通过HttpWebRequest请求https接口

    一.为什么进行代理接口的开发: 有些项目需要访问被墙了哒网站,比如前不久公司开发项目需要使用google地图的接口,而google在中国被墙了,所有打算做一个代理接口服务,将代理放到国外服务器上,通过 ...

  4. webapi 利用webapiHelp和swagger生成接口文档

    webapi 利用webapiHelp和swagger生成接口文档.均依赖xml(需允许项目生成注释xml) webapiHelp:微软技术自带,仅含有模块.方法.请求-相应参数的注释. swagge ...

  5. 利用JQUERY实现多个AJAX请求等待

    利用JQUERY实现多个AJAX请求等待 li {list-style-type:decimal;}.wiz-editor-body ol.wiz-list-level2 > li {list- ...

  6. 对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App)

    对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App) 实验目的:对比使用Charles和Fiddler两个工具 实验对象:车易通App,易销通App 实验结果 ...

  7. 利用Laravel 搭建oauth2 API接口 附 Unauthenticated 解决办法

    利用Laravel 搭建oauth2 API接口 要求 laravel 5.4以上 安装 $ composer require laravel/passport 在配置文件 config/app.ph ...

  8. 利用抖音Cookie充值接口提取支付链接,个人调起原生微信h5支付宝h5支付

    最近开始搞一些个人支付通道的开发,方便个人不用和第三方平台签约就能收款,省去很多流程手续的成本. 然后翻了一下网上并没有太多现成的技术教程,只能自己研究着搞了. 这次要分享的是利用抖音的充值接口,去分 ...

  9. xmlrpc实现bugzilla api调用(无会话保持功能,单一接口请求)

    xmlrpc实现bugzilla4   xmlrpc api调用(无会话保持功能,单一接口请求),如需会话保持,请参考我的另外一篇随笔(bugzilla4的xmlrpc接口api调用实现分享: xml ...

随机推荐

  1. laravel如何引用外部文件

    (1).首先在app\Http\routes.php中定义路由: 1 2 3 Route::get('view','ViewController@view'); Route::get('article ...

  2. git clean解决 GIT error: The following untracked working tree files would be overwritten

    git clean用法:https://www.cnblogs.com/lsgxeva/p/8540476.html :

  3. spring cloud 服务治理 - Eureka

    前言 在分布式系统领域有个著名的CAP定理: C——数据一致性: A——服务可用性: P——服务对网络分区故障的容错性. 这三个特性在任何分布式系统中不能同时满足,最多同时满足两个. Zookeepe ...

  4. [转帖]AWR报告参数:DB TIME和DB CPU

    AWR报告参数:DB TIME和DB CPU http://blog.itpub.net/12679300/viewspace-1182396/ 一.前言:AWR报告是了解ORACLE运行的一个重要报 ...

  5. 『磁力块 bfs 分块』

    磁力块 Description 在一片广袤无垠的原野上,散落着N 块磁石.每个磁石的性质可以用一个五元组 (x,y,m,p,r)描述,其中x,y 表示其坐标,m 是磁石的质量,p 是磁力,r 是吸引半 ...

  6. SpringBoot与PageHelper的整合示例详解

    SpringBoot与PageHelper的整合示例详解 1.PageHelper简介 PageHelper官网地址: https://pagehelper.github.io/ 摘要: com.gi ...

  7. 【C#】58. .Net中的并发集合——BlockingCollection

    https://blog.csdn.net/huiwuhuiwu/article/details/53608269 这篇是并发集合中的最后一篇,介绍一下BlockingCollection.在工作中我 ...

  8. c++打印实心菱形,空心三角形,十字星,空心正方形,实心平行四边形

    今天翻资料的时候,无意间发现了一个文件,是刚接触编程的时候用c++写的一段程序,我称之为"图形打印机",想着把所有图形都打印出来,后来发现其实每种图形的代码都是一个思路,就不想做重 ...

  9. SQL Server中查找包含某个文本的存储过程 SQL 查找存储过程中出现过的文字怎么查询 查询整个数据库中出现的文本 sql 全局搜索

    --将text替换成你要查找的内容SELECT name, *FROM sysobjects o, syscomments sWHERE o.id = s.id AND text LIKE '%tex ...

  10. 调用日志输出错误:TypeError: 'int' object is not callable等

    *)TypeError: 'int' object is not callable 错误信息: Traceback (most recent call last): File "Visual ...