karate - 配置 Karate Mock 以使用具有 JSON、XML 以外的内容类型的 API
问题描述
我需要使用 Karate Mock 来模拟一个 API,它接受以下 Content-Type 的消息并做出相应的响应
'Content-Type: application/x-www-form-urlencoded'
我尝试在功能文件中对其进行如下配置,但遇到了以下问题。我猜默认情况下它接受 JSON 作为内容类型,有没有办法配置模拟来读取像这样的自定义消息。
实际 API 调用:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "elem_value=generic_value&address=" http://myhost:9090/api/resource_path
模拟功能文件:
Scenario: pathMatches('/api/resource_path') && typeContains('urlencoded')
* def responseStatus = 200
* def response = read ('/payload/Success.json')
* print response
实际错误:
Caused by: <eval>:1 ReferenceError: "generic_value" is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1441)
at jdk.nashorn.internal.scripts.Script$43$\^eval\_.:program(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)
解决方案
这应该已在较新版本的空手道中修复,请尝试升级。
我认为它将在 0.9.2 - https://github.com/intuit/karate/issues/649
推荐阅读
- c# - 如何将 OAuth 与 Office 365 报告 Web 服务结合使用
- c# - 为什么我不能在这里使用 SQLite 命令生成器?
- python - 使用多处理池在 python 中加速 TFLite 推理
- angular - 在 npm 上拆分和发布后如何维护 Angular 模块
- c# - 使用 C# 对象创建复杂的 JSON
- mql4 - MQL4 问题 如何在 EA 中打开多个订单
- docker - phpmyadmin 无法使用 docker-compose 连接到 mariadb:数据包乱序
- oop - 在使用 »super« 之前访问静态方法
- r - R如何根据现有数据创建列/特征
- python - scrapy 中的项目加载器字段是否可重用?