node.js - 如果我用 axios 调用 digisigner 文档 api,则会出现错误请求错误
问题描述
如果我从邮递员那里调用 DigiSigner,它工作正常,但是如果我使用 axios form nodejs 应用程序调用它,它会给出错误错误请求。
这是我的代码示例。
const digi_signer_url = "https://api.digisigner.com/v1/documents";
const digi_signer_options = {
method: 'POST',
headers: { "Content-Type": "multipart/form-data", 'Authorization': `Basic ${process.env.DIGI_SIGNER_KEY}` },
data: {file: file},
url: digi_signer_url,
}
const r = axios(digi_signer_options)
解决方案
这是解决方案。
const opts = {
method: 'POST',
url: 'https://api.digisigner.com/v1/documents',
headers:
{
'cache-control': 'no-cache',
authorization: `Basic ${process.env.DIGI_SIGNER_KEY}`,
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
},
formData:
{
file:
{
value: fs.createReadStream(path.join(__dirname, '../../templates/sample-po.pdf')),
options: { filename: 'sample-po.pdf', contentType: null }
}
}
};
request(opts, function (error, response, body) {
if (error) throw new Error(error);
if (body) {
const document = JSON.parse(body);
const {document_id} = document;
const send_to_signature = {
method: 'POST',
url: 'https://api.digisigner.com/v1/signature_requests',
headers:
{
'cache-control': 'no-cache',
'content-type': 'application/json',
authorization: `Basic ${process.env.DIGI_SIGNER_KEY}`
},
body:
{
documents:
[{
document_id: document_id,
subject: subject,
message: content,
signers:
[{
email: to_email,
fields: [{ page: 0, rectangle: [0, 0, 200, 100], type: 'SIGNATURE' }]
}]
}]
},
json: true
};
request(send_to_signature, function (error, response, result) {
if (error) throw new Error(error);
console.log(result)
});
}
});
推荐阅读
- c# - 以编程方式将新列添加到 DataGridView(填充有 DataTable 的 DataGridview)
- javascript - JavaScript 条件量角器测试
- python - UnicodeDecodeError:“utf-8”编解码器无法解码字节 0xff
- django - 在 django 中进行查询并返回我所有对象的总和
- openshift - 如何在 eclipse-che 中加载 dockerimage?
- r - 如何在热图上更改颜色等
- javascript - 我如何在firebase中使用这个“创建于”字段来使用toDate()在javascript中获取日期?
- pimcore - 多选呈现为文档中的标签
- angular - 如何用分页过滤整个表格?
- uiwebview - 无法从 IOS 构建中删除对 UIWebView 的引用。(Xcode 11.5,斯威夫特 5)