java RestAssured:get()方法,其中包含“%2B”(加号)的URL

时间:2018-06-15 06:01:35

标签: java rest-assured web-api-testing

我正在点击一个带有加号的网址。 URL的示例如下:

https://api.digitalvault.cloud/<someText>/<someText>/samples?v=2.1&<someText>&startTime=2018-06-14T19:54:34%2b08:00&endTime=2018-06-14T01:54:34%2b08:00.

但它没有采用%2b符号来表示加号。以下是我的代码:

RestAssured.given()
    .config(RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation()))
    .header("Authorization", Authorization).header(HeaderParameter1, HeaderParameterValue1)
    .header(HeaderParameter2, HeaderParameterValue2).get(URI);

其中URI是实际网址。

有人可以建议处理这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

String result = java.net.URLDecoder.decode(url, "UTF-8");

示例:

String url = "https://api.digitalvault.cloud/<someText>/<someText>/samples?v=2.1&<someText>&startTime=2018-06-14T19:54:34%2b08:00&endTime=2018-06-14T01:54:34%2b08:00";
System.out.println("Before ENCODING: "+url);
String result = java.net.URLDecoder.decode(url, "UTF-8");
System.out.println("After ENCODING: "+result);