rest-assured的官方文檔地址:
https://github.com/rest-assured/rest-assured/wiki/Usage#serialization
1、首先導入包 import static io.restassured.RestAssured.*; import io.restassured.response.ValidatableResponse; 2、無參的get請求,加結果輸出 ValidatableResponse result = when().get(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 3、有參的get請求,加結果輸出 ValidatableResponse result = given().params(map). when().get(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 4、json的post請求,加結果輸出(注意:參數是bogy) ValidatableResponse result= given(). contentType("application/json"). body(map). when(). post(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 5、form-data的post請求,加結果輸出(注意:參數是params) ValidatableResponse result= given(). params(map1). when(). post(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString());