【问题标题】:Karate: Query Param values are getting encoded空手道:查询参数值正在被编码
【发布时间】:2018-12-04 19:15:08
【问题描述】:

我正在使用 karate 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

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

【问题讨论】:

    标签: bdd karate queryparam


    【解决方案1】:

    其实没有错,

    需要使用 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'
    

    如果您尝试通过任何特殊的 这里面的人物。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      相关资源
      最近更新 更多