【发布时间】:2019-07-14 04:24:21
【问题描述】:
我在尝试向使用 swagger 2.0(不是我)创建的 API 发出发布请求时遇到了一些麻烦。
我已经向邮递员导入了一个集合,当我执行一个发布请求时,它可以完美运行。但是在 Node.js 中,它使用 swagger 库输出 400 错误,使用 axios 输出 500。
这是该集合在邮递员中提供的架构:
{
"workflowFunctionID": 1,
"workflowActionParameters": [
{
"name": "Description",
"value": "Probando y wea2",
"workflowFunctionParameterId": 2
},
{
"name": "Price",
"value": "25000",
"workflowFunctionParameterId": 3
}
]
}
正如我所提到的,它运行良好。这是当前使用 Node.js 的代码:
main = async() => {
try {
const token = await acquireTokenWithClientCredentials(RESOURCE, CLIENT_APP_Id, CLIENT_SECRET, AUTHORITY);
const request = {
url: `${WORKBENCH_API_URL}/api/v1/contracts?workflowId=1&contractCodeId=1&connectionId=1`,
method: "POST",
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token.access_token}` },
body: {
workflowActionInput: {
workflowFunctionID: 1,
workflowActionParameters: [{
"name": "description",
"value": "cualkier wea"
},
{
"name": "price",
"value": "20000000"
}
]
}
}
}
let res = await Swagger.http(request);
console.log(res);
}
catch (err) {
console.error(err);
}
}
main();
我应该如何将正文/表单数据传递给发布请求,或者使用其他包或代码?提前感谢您的帮助。
【问题讨论】:
标签: node.js swagger postman swagger-2.0