api - 空手道 API:忽略“?” 在网址中
问题描述
我正在使用 Karate API 框架中的 path 关键字来发出请求。路径存储在从另一个特征文件返回的变量中。但是,我无法通过“?”。这是我正在做的事情:
我有一个“paths.feature”文件,可以获取后续请求的所有路径。以下是返回路径的示例:
/LegalEntity/{legalEntityId}/taxidentifier/{Id}?formId=captureCustomerContact&subformid=taxIdentifierSimplified
然后我“替换”如下参数:
/LegalEntity/43/taxidentifier/13?formId=captureCustomerContact&subformid=taxIdentifierSimplified
然后我从新的功能文件中调用此功能文件并将存储的变量 (def) 传递到路径中,但是,URL 不会忽略“?” 并且测试失败。任何指示或帮助将不胜感激。谢谢
错误
/LegalEntity/43/taxidentifier/13%3FformId=captureCustomerContact&subformid=taxIdentifierSimplified
解决方案
我认为您很困惑,这与调用功能无关。
当 a 中有特殊字符时path
,它将被编码。这就是 HTTP 的工作原理。参考:https ://stackoverflow.com/a/54477346/143475
尝试以下 3 行测试,看看会发生什么:
* url 'https://httpbin.org'
* path 'anything/?'
* method get
实际发送的 URL 将是:https://httpbin.org/anything/%3F
但是您需要了解正确使用关键字?
时会自动插入:param
* url 'https://httpbin.org'
* path 'anything'
* param foo = 'bar'
* method get
这里的 URL 将是:https://httpbin.org/anything?foo=bar
因此,您应该做的是重构您的测试以通过formId
并subformid
作为查询参数,例如:
* def someVariable = 'captureCustomerContact'
* url 'https://httpbin.org'
* path 'anything'
* param formId = someVariable
* method get
请花一些时间来研究它是如何工作的。这里的 URL 将是https://httpbin.org/anything?formId=captureCustomerContact
,当然,你可以有更多的param
实例。请阅读文档:https ://github.com/karatelabs/karate#param
推荐阅读
- node.js - 如何在 node.js 中获取与 TypeScript 文件行数相关的错误信息?
- access-token - IdentityServer4 访问令牌生命周期
- javascript - Owl Carousal auto refresh even when single image is there singleItem mode
- hadoop - HBase 行键范围分配
- python - Python - 连接特定目录中的 CSV 文件
- apache-spark - Apache Spark 2.1 中缺少 LinearSVC?Spark 2.2 中的非线性内核?
- java - 使用 Java Stream API 对 BigDecimal 进行分组和累加
- c++ - Boost Beast编译错误
- php - 如何在 PHP 的 SOAP API 中调用和设置标头和函数中的参数?
- regex - 如何从 html 文件中提取 URL 路径?(在 bash 中)