RestAssured删除方法返回状态码405

时间:2020-07-04 15:07:07

标签: rest-assured http-delete

RestAssured Delete方法返回状态代码为405,但是当我从邮递员尝试时,它返回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 is\t" + Resp);
}

1 个答案:

答案 0 :(得分:1)

您在“确保安全”代码中犯了一个错误,请在.log().all()之后添加given()以查看请求流量,然后您就可以看到错误

我对代码做了很少的更改,希望它对您有用

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();
}