RestAssured Delete 方法返回状态代码为 405,但当我从 Postman 尝试时,它返回 202(这是预期的(
在邮递员:
方法 : 删除
PATH : .../rest/end1/end2?name=xyz
法典:
String name = "xyz";
String baseURI = System.getProperty("environmentPathUrl");
String path = "/rest/end1";
public void deleteName(String baseURI, String path, String name) {
String Resp = RestAssured.given().baseUri(baseURI).basePath(path).queryParam("name", name).when()
.delete("/end2").then().assertThat().statusCode(202).and().extract().response().asString();
System.out.println("Response ist" + Resp);
}
您在放心代码中犯了一个错误,请在given()
后添加一个.log().all()
以查看请求流量,您将能够看到您的错误
我对代码进行了一些更改,希望这对您有用
public static void deleteName() {
String name = "xyz";
String baseURI = System.getProperty("environmentPathUrl");
String path = "/rest/end1";
String Resp = RestAssured.given().log().all().baseUri(baseURI).basePath(path).queryParam("name", name).when()
.delete("/end2").then().assertThat().statusCode(202).and().extract().response().asString();
System.out.println("Response ist" + Resp);
}
public static void main(String[] args) {
deleteName();
}