如何使用 Rest Assured 在 GET url 中传递查询字符串参数?
How to pass Query String Parameters in GET url using Rest Assured?
如何使用 Rest Assured 在 GET url 中传递查询字符串参数?
URL 是:http://example.com/building
我的查询字符串是:
globalDates:{"startMs":1473672973818,"endMs":1481448973817,"period":90}
limitTo:6
loadTvData:true
startFrom:0
userId:5834fb36981baacb6a876427
您可以将它们作为查询参数传递..
given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get("http://example.com/building"). ...
您可以像这样使用 Rest Assured 在 GET URL 中传递查询字符串参数:
when()
.parameter("globalDates","startMs","1474260058054","endMs","1482036058051","period","90")
.parameters("limitTo","6")
.parameters("loadTvData","true")
.parameters("startFrom","0")
.parameters("userId","5834fb36981baacb6a876427");
你也可以像下面这样把这个查询参数放在地图中,
HashMap<String, String> params = new HashMap<String, String>() {{
put("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}");
put("limitTo","6" );
,...
}}
并且post如下,
resp = RestAssured.given()
.headers(headers)
.queryParameters(params)
.post(apiURL).andReturn();
对于我们的 api 类型如下:
https://my.api.com/meeting?page=0&size=1
我们有:
Response response = requestSpecification.queryParam("page", 0).queryParam("size", 1).get(baseEndpoint);
QueryParam can be passed as:
String endpoint = "http://example.com/building";
var response = given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get(endpoint).then();
如何使用 Rest Assured 在 GET url 中传递查询字符串参数?
URL 是:http://example.com/building
我的查询字符串是:
globalDates:{"startMs":1473672973818,"endMs":1481448973817,"period":90}
limitTo:6
loadTvData:true
startFrom:0
userId:5834fb36981baacb6a876427
您可以将它们作为查询参数传递..
given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get("http://example.com/building"). ...
您可以像这样使用 Rest Assured 在 GET URL 中传递查询字符串参数:
when()
.parameter("globalDates","startMs","1474260058054","endMs","1482036058051","period","90")
.parameters("limitTo","6")
.parameters("loadTvData","true")
.parameters("startFrom","0")
.parameters("userId","5834fb36981baacb6a876427");
你也可以像下面这样把这个查询参数放在地图中,
HashMap<String, String> params = new HashMap<String, String>() {{
put("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}");
put("limitTo","6" );
,...
}}
并且post如下,
resp = RestAssured.given()
.headers(headers)
.queryParameters(params)
.post(apiURL).andReturn();
对于我们的 api 类型如下:
https://my.api.com/meeting?page=0&size=1
我们有:
Response response = requestSpecification.queryParam("page", 0).queryParam("size", 1).get(baseEndpoint);
QueryParam can be passed as:
String endpoint = "http://example.com/building";
var response = given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get(endpoint).then();