【问题标题】:Can't GET with matrix parameter using Rest-assured无法使用 Rest-assured 获取矩阵参数
【发布时间】:2016-02-14 01:18:08
【问题描述】:

我的请求如下所示:

http://localhost:8080/car/bmw;color=red

返回汽车的型号和颜色作为 json 数据。 如果我在没有指定颜色的情况下执行请求,它将默认为绿色。

还有Java代码:

String resourcePath = "http://localhost:8080/"
String carModel= "bmw"
String color = "red"

 RestAssuredResponseImpl response =
 (RestAssuredResponseImpl) given().
     when().get(resourcePath + "car/" + carModel + ";color=" + color );

当我将 url 复制/粘贴到浏览器中时,它会按预期返回 json,但是当我尝试放心获取它时,我会收到 404 not found 错误。 我尝试使用 param("color",color) 发送请求,但它只是忽略参数并返回默认 json。

【问题讨论】:

标签: json rest rest-assured


【解决方案1】:

似乎还不支持矩阵参数。今天(2020 年 1 月)这仍然是对 RestAssured 的开放功能请求:https://github.com/rest-assured/rest-assured/issues/417

推荐的解决方法是关闭 URL 编码。

given().urlEncodingEnabled(false)
    .when()
    .get("http://localhost:8080/car/bmw;color=red");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 2019-07-04
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多