霍格沃兹测试开发学社 ceshiren.com
{style=zoom:60%}
title 使用代理之前
scale 200 width
scale 400 height
autonumber
participant 客户端 as client
participant 服务端 as server
client -> server: 发起请求
server -> client: 返回响应
title 使用代理之后
scale 200 width
scale 400 height
autonumber
participant 客户端 as client
participant 代理 as proxy
participant 服务端 as server
client -> proxy: 发起请求
proxy -> server: 转发请求
server -> proxy: 返回响应
proxy -> client: 转发响应
proxy()
方法proxy
对象import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.specification.ProxySpecification.host;
public class TestHttpProxyConf {
@Test
void testHTTPProxy() {
// 定义一个代理的配置信息
RestAssured.proxy = host("localhost").withPort(8888);
given()
.proxy(8888) // 设置代理
.when()
.get("http://httpbin.org/get") // 发送 HTTP请求
.then()
.log().all() // 打印完整响应信息
.statusCode(200); // 响应断言
}
}
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.specification.ProxySpecification.host;
public class TestHttpsProxyConf {
@Test
void testHTTPProxy() {
// 定义一个代理的配置信息
RestAssured.proxy = host("localhost").withPort(8888);
given()
.relaxedHTTPSValidation() // 忽略HTTPS校验
.when()
.get("https://httpbin.ceshiren.com/get")
.then()
.log().all() // 打印完整响应信息
.statusCode(200); // 响应断言
}
}