当尝试向使用 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();
我应该如何将正文/表单数据传递给发布请求,或者使用另一个包或代码?预先感谢您的任何帮助。