[英]How can we make a POST service call which takes formdata instead of json in OpenTest?
我们有一个 WebService,它以formData
键值对作为请求,而不是 json。 使用openTest
我们如何传递这些formData
? 基本上,我们需要一个代码片段来使用OpenTest
yaml 脚本发布formData
。
下面是示例 curl 命令,我们需要使用 OpenTest 发布它,其中 Content-Type 为 multipart/form-data
`
curl --location --request POST 'https://serviceurl.com/getacb' \
--form 'userKey=a1b23' \
--form 'apiKey=1_ffER_hk6Rb89--2EElfsdeF3' \
--form 'secret=Ude+6NIjojo89/gyAB7huGS5' \
--form 'targetUID=ulknnk4kjlkj5'
`
我们正在寻找一个示例片段来发布上述多部分/表单数据。
在将其传递给下一个操作之前,您需要自己构建 FormData() object。
var data = new FormData();
data.append("userKey", "a1b23");
data.append("apiKey", "1_ffER_hk6Rb89--2EElfsdeF3");
data.append("secret", "Ude+6NIjojo89/gyAB7huGS5");
data.append("targetUID", "ulknnk4kjlkj5");
这是对OpenTest API 测试 YAML进行了一些修改的示例。
description: Example Post based off SO Question
actors:
- actor: ACTOR1
segments:
- segment: 1
actions:
- description: Create a random post ID
script: |
var data = new FormData();
data.append("userKey", "a1b23");
data.append("apiKey", "1_ffER_hk6Rb89--2EElfsdeF3");
data.append("secret", "Ude+6NIjojo89/gyAB7huGS5");
data.append("targetUID", "ulknnk4kjlkj5");
- description: Send a request to getacb
action: org.getopentest.actions.HttpRequest
args:
url: https://serviceurl.com/getacb
headers:
Content-Type: multipart/form-data
verb: POST
body: data
- description: Extract the response's status code and body
script: |
var statusCode = $output.statusCode;
var postInfo = $output.body;
- description: Validate the response status code
script: |
if (statusCode != 201) {
$fail($format(
"We expected the status code to be {0} but it was {1}",
201,
statusCode));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.