首页 > 解决方案 > 空手道:查询参数值正在被编码

问题描述

我正在使用空手道 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 Andurl?Name=test+data

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

标签: bddkaratequeryparam

解决方案


其实并没有错,

需要 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 被编码,请不要使用路径、参数、参数定义来构建您的 URL。

相反,将整个 URL 构建为字符串并将其传递给url. 像,

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

如果您尝试在其中传递任何特殊字符,您可能会遇到异常。

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


推荐阅读