首页 > 解决方案 > 在 Postman 中获取 200 个代码,但在通过放心自动执行相同请求时获取 400 个代码

问题描述

在此处输入图像描述

在此处输入图像描述

在邮递员中,我可以获得 200 个状态代码,但是当我尝试使用放心自动化它时,我收到 400 个错误。

public class trial {
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        RestAssured.baseURI="https://api.planet.com";
        Response res=given().
        header("Authorization", "api-key ab2118c30721496495ddc8d4f3603d69").
        header("Content-Type", "application/json").
        queryParam("strict", "false").
        body("{" + 
                "  \"filter\": {  " + 
                "   \"type\":\"AndFilter\"," + 
                "   \"config\": [" + 
                "       {  " + 
                "         \"type\":\"RangeFilter\"," + 
                "         \"field_name\":\"cloud_cover\"," + 
                "         \"config\":{ " + 
                "            \"lte\":0.5" + 
                "         }" + 
                "       }" + 
                "  ]" + 
                "   " + 
                "}," + 
                "  \"item_types\": [\"PSScene3Band\"]," + 
                "  \"name\": \"Assignment\"" + 
                "}").
                when().
                post("/data/v1/searches/").
                then().assertThat().statusCode(200).and().contentType(ContentType.JSON).
                extract().response();

        JsonPath js=ReusableMethods.rawToJson(res);
        System.out.println(res.getBody().asString());

    }

}

标签: javarestapiautomationhttp-status-code-400

解决方案


推荐阅读