Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

bdd - Karate: Query Param values are getting encoded

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...