RestAssured 删除方法 returns 状态码 405

RestAssured delete method returns status code 405

RestAssured Delete 方法 returns 状态代码为 405 但是当我从 Postman 尝试时 returns 202(这是预期的)

在邮递员中:

方法:删除

路径:.../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 is\t" + Resp);
}

你的Rest Assured代码有误,在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 is\t" + Resp);
}

public static void main(String[] args) {

    deleteName();
}