Karate: Query Param values are getting encoded

南楼画角 提交于 2020-01-25 11:24:30

问题


I am using karate 0.6.1 version and facing issue with get request with queryparam.

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'|

in the request url with queryparam becomes like url?Name=Volvo%25 And url?Name=test+data

which is not correct, how should i resolve that.


回答1:


It is actually not wrong,

Url encoding is required to differentiate between special characters in your data vs special characters that are reserved to construct the URL.

Reserved Characters URL Encoding:

:   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 +

so if you are going to pass any special characters as data via URL you need to % encode them to avoid conflicts.

In karate, if you want to avoid your URL getting encoded, don't construct your URL using path, params, param definitions.

Instead, build your entire URL as a string and pass it to url. like,

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

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

so consider encoding the URL if you are going to pass any special characters.



来源:https://stackoverflow.com/questions/53619941/karate-query-param-values-are-getting-encoded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!