bdd - 空手道:查询参数值正在被编码
问题描述
我正在使用空手道 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
这是不正确的,我该如何解决。
解决方案
其实并没有错,
需要 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 进行编码。
推荐阅读
- javascript - 在 Javascript 中指定文档元素
- android - 从命令行构建具有动态功能模块的 apk,无需 bundletool
- javascript - 是否可以在 Azure 中使用 sendgrid 发送电子邮件而不调用 context.done?
- javascript - 从 Chrome 浏览器中的嵌入元素打印 PDF
- java - Java 流 API 过滤器
- python - 在一次迭代中在 pandas 中标记包含关键字(关键字是列名)的“真”行
- java - 在 Kotlin 中将字符串编码为 UTF-8
- twitter-bootstrap - 仅在 XS 屏幕上显示 Bootstrap 4 导航栏折叠
- r - 传递函数模型
- web-scraping - 如何在 div 中获取 2 个不同的类文本