空手道:查询参数值正在编码

Karate: Query Param values are getting encoded

我正在使用 空手道 0.6.1 版本并面临 get 查询参数请求的问题。

Scenario Outline: Verify the response Data with account details when there are filter values are provided with wildcard

 Given params { <paramName>: <paramValue> }
 When method get
 Then status 200
 Examples:
   | paramName | paramValue |                                                                                                                                                                                                                                                 
   | Name       |  'Volvo%' |
   | Name       |  'test data'|

在带有 queryparam 的请求 url 中变得像 url?Name=Volvo%25 并且 url?Name=test+data

这不正确,我该如何解决。

其实并没有错,

需要

Url 编码来区分数据中的特殊字符与保留用于构造 URL.

的特殊字符

保留字符URL编码:

:   Separate protocol (http) from address encoded as %3B
/   Separate domain and directories encoded as %2F
#   Separate anchors encoded as %23
?   Separate query string encoded as %3F
&   Separate query elements encoded as %24
@   Separate username and password from domain encoded as %40
%   Indicates an encoded character encoded as %25
+   Indicates a space encoded as %2B
<space> Not recommended in URLs encoded as %20 or +

因此,如果您要通过 URL 将任何特殊字符作为数据传递,您需要 % encode 它们以避免冲突。

在空手道中,如果您想避免 URL 被编码,请不要使用 path、params、param 定义来构建 URL。

相反,将整个 URL 构建为字符串并将其传递给 url。喜欢,

* url 'http://httpbin.org/get?Name=Stark'

You might get an exception if you are trying to pass any special characters in this.

因此,如果您要传递任何特殊字符,请考虑对 URL 进行编码。