我能够将JSON数据作为查询参数传递,其中我以HasMap的形式传递特定的HasMap。现在,我希望API只返回与指定的kit_config_id相关的数据,但它给了我所有的记录。
我在这里做什么坏事?
// Request object using RestAssured
RequestSpecification httpRequest = RestAssured.given();
HashMap<String, String> params = new HashMap<String, String>();
params.put("kit_config_id", "60db53ec7a334172b005b692");
Response response = httpRequest.given().baseUri("https://qa-api-test.com").param("query", params).when().get("/imageProps");GET调用的完整网址是:https://qa-api-tests.com/imageProps?params={"query": {"kit_config_id": "60db53ec7a334172b005b692"}}
发布于 2021-06-30 01:05:45
如果你想要这样的查询
/imageProps?params={"query":{"kit_config_id":"60db0d5d7a334172b005b665"}}使用此方法:
HashMap<String, Object> kit_config = new HashMap<>();
kit_config.put("kit_config_id", "60db0d5d7a334172b005b665");
HashMap<String, Object> query = new HashMap<>();
query.put("query", kit_config);
RestAssured.given().log().all().baseUri("your-url")
.queryParams("params", query)
.when().get("/imageProps");如果你想要这样的查询
/imageProps?kit_config_id=60db53ec7a334172b005b692只是需要:
HashMap<String, Object> kit_config = new HashMap<>();
kit_config.put("kit_config_id", "60db0d5d7a334172b005b665");
RestAssured.given().log().all().baseUri("https://postman-echo.com")
.queryParams(kit_config)
.when().get("/imageProps");https://stackoverflow.com/questions/68183825
复制相似问题