JSON 字符串形式的正文
JSON body in string form
我试图在 POST 方法的 HTTP 请求中发送 json 正文,但问题是一些字符串实际上是 JSON 字符串形式,所以有一些棘手的问题需要引用才能正确。
这是运行良好的 CURL 命令:
curl -X POST https://www.example.com:8080/api/v1/runs -H "accept: application/json" -H "Content-Type: multipart/form-data" -F tags='{"revision":"master" }' -F params='{"a":"b"}' -F type=testflow -F wurl=https://github.com/abc/repo
空手道POST要求:
给定路径 '/api/v1/runs'
并请求 "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }"
但是抛出一个错误:
features.wapi.post_wrun: wapi.post_wrun.feature:14 - 评估 (js) failed: "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }", <eval>:1:12 Expected ; but found revision "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }"
^ 在第 1 行第 12 列
我试过以下方法:
- 我已经把内容放在 Json 文件中,例如:
{ "url": "https://github.com/abc/repo", "type": "testflow", "tags": { "revision": "master" }, "params": { "a": "b" } }
def readJsonbody = read ("../test/feature/test.json").
def readJSOnbody = karate.readJsonbody("classpath:test.json")
但似乎运气不好,如果需要任何棘手的引用来解决这个问题,请告诉我,它在 CURL 中工作正常但在 POST 使用 Karate 的请求中不工作?
谢谢,
S
使用text
:https://github.com/intuit/karate#text
* text body =
"""
{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }
"""
* request body
另请注意,karate.readAsString()
也可以:https://github.com/intuit/karate#read-file-as-string
也就是说,我认为 -F
在 cURL 中意味着 form-fields,因此您可能需要做一些完全不同的事情:https://github.com/intuit/karate#form-field
* form field tags = '{"revision":"master"}'
* form field params = '{"a":"b"}'
依此类推然后一个post
.
我试图在 POST 方法的 HTTP 请求中发送 json 正文,但问题是一些字符串实际上是 JSON 字符串形式,所以有一些棘手的问题需要引用才能正确。
这是运行良好的 CURL 命令: curl -X POST https://www.example.com:8080/api/v1/runs -H "accept: application/json" -H "Content-Type: multipart/form-data" -F tags='{"revision":"master" }' -F params='{"a":"b"}' -F type=testflow -F wurl=https://github.com/abc/repo
空手道POST要求:
给定路径 '/api/v1/runs'
并请求 "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }"
但是抛出一个错误:
features.wapi.post_wrun: wapi.post_wrun.feature:14 - 评估 (js) failed: "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }", <eval>:1:12 Expected ; but found revision "{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }"
^ 在第 1 行第 12 列
我试过以下方法:
- 我已经把内容放在 Json 文件中,例如:
{ "url": "https://github.com/abc/repo", "type": "testflow", "tags": { "revision": "master" }, "params": { "a": "b" } }
def readJsonbody = read ("../test/feature/test.json").
def readJSOnbody = karate.readJsonbody("classpath:test.json")
但似乎运气不好,如果需要任何棘手的引用来解决这个问题,请告诉我,它在 CURL 中工作正常但在 POST 使用 Karate 的请求中不工作?
谢谢, S
使用text
:https://github.com/intuit/karate#text
* text body =
"""
{ tags: '{"revision":"master"}', wurl: 'https://github.com/abc/repo', params: '{"a":"b"}', type: 'testflow' }
"""
* request body
另请注意,karate.readAsString()
也可以:https://github.com/intuit/karate#read-file-as-string
也就是说,我认为 -F
在 cURL 中意味着 form-fields,因此您可能需要做一些完全不同的事情:https://github.com/intuit/karate#form-field
* form field tags = '{"revision":"master"}'
* form field params = '{"a":"b"}'
依此类推然后一个post
.