如何在url中转义等号?

ki1q1bka  于 2021-08-25  发布在  Java
关注(0)|答案(2)|浏览(339)

在我的重新授权测试中,我有:

String customerId = "1234";

given().queryParam("customerId=" + customerId)
        .spec(customerApi).auth().oauth2(token)
.when().log().ifValidationFails()
       .get("/api/v1/customers/latest")
.then()
       .assertThat()
       .statusCode(201);

…其中我需要传递一个带有 = 烧焦
其编码如下:

https://customer-api.com/api/v1/customers/latest?customerId%3D1234

解决这个问题最干净的方法是什么?

bhmjp9jg

bhmjp9jg1#

您正在将参数名和值作为参数名传递给restasured,然后restasured将被转义。只需将参数的实际值作为 queryParam(String, Object...) . 如有必要,库将负责参数名称或值的转义。

.queryParam("customerId", customerId)

这将导致以下情况:

https://customer-api.com/api/v1/customers/latest?customerId=1234
pepwfjgg

pepwfjgg2#

解码最后的url String url = URLDecoder.decode("https://customer-api.com/api/v1/customers/latest?customerId%3D1234", StandardCharsets.UTF_8);

相关问题