REST Assured 15 - RequestSpecification Call Http方法

这篇博客介绍了如何使用RESTAssured库中的RequestSpecification进行HTTP请求。通过given()方法创建请求规范,设置BaseURI和BasePath后,可以直接调用get()等HTTP方法。此外,也可以将请求规范作为参数传递给given()的重载方法或spec()方法来执行请求,展示了RESTAssured的灵活性。
摘要由CSDN通过智能技术生成

REST Assured 系列汇总 之 REST Assured 15 - RequestSpecification Call Http方法

上一篇我们已经了解了Rest Aassured中Request Specification,对于初学者最大的疑惑就是有多种试方式执行相同的行为。
下面的例子是RequestSpecification多种方式调用http 方法

import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
 
public class DifferentWaysOfCallingHttpMethodsOnRequestSpecifications {
	
	
	public static void main(String[] args) {
		
		// Creating request specification using given()
		RequestSpecification request1= RestAssured.given();
		// Setting Base URI
		request1.baseUri("https://restful-booker.herokuapp.com");
		// Setting Base Path
		request1.basePath("/booking");
		
		
		// We can directly call http verbs on RequestSpecification
		Response res1= request1.get();
		System.out.println(res1.asString());
		
		// We can also pass RequestSpecification reference variable in overloaded given() method
		Response res2 = RestAssured.given(request1).get();
		System.out.println(res2.asString());
		
		// We can also pass RequestSpecification using spec() method
		Response res3 = RestAssured.given().spec(request1).get();
		System.out.println(res3.asString());
		
	}
 
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值