空手道:查询参数值正在编码 [英] Karate: Query Param values are getting encoded
问题描述
我正在使用空手道0.6.1 版本,并遇到带有queryparam的get
请求的问题.
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'|
使用queryparam的请求URL中的
变得像url?Name=Volvo%25
还有url?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.
推荐答案
实际上没错,
需要使用网址编码来区分数据中的特殊字符和保留用于构造URL的特殊字符.
Url encoding is required to differentiate between special characters in your data vs special characters that are reserved to construct the 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
以避免冲突.
so if you are going to pass any special characters as data via URL you need to % encode
them to avoid conflicts.
在空手道中,如果要避免对URL进行编码,请不要使用路径,参数,参数定义来构造URL.
In karate, if you want to avoid your URL getting encoded, don't construct your URL using path, params, param definitions.
相反,将整个URL构造为字符串并将其传递给url
.喜欢,
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.
因此,如果您要传递任何特殊字符,请考虑对URL进行编码.
so consider encoding the URL if you are going to pass any special characters.
这篇关于空手道:查询参数值正在编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!