javascript - JSReport请求错误
问题描述
我正在尝试访问 jsreport api 以呈现报告模板,但出现以下错误:
{
body: "{"body":"\"{\\\"template\\\":{\\\"shortid\\\":\\\"B1z8vSImQ\\\"}}\"","status":400,"statusCode":400}",
code: 500,
headers: {
connection: "close",
content-length: "99",
content-type: "application/json; charset=utf-8",
date: "Mon, 16 Jul 2018 14:22:54 GMT",
etag: "W/"63-y7OYa6jmSZpY//j8j8VDr2CKCZg"",
server: "nginx/1.15.0",
x-powered-by: "Express"
}
}
这是我调用 api 的方式:
const options = {
method: 'POST',
//strictSSL: false,
headers: {
'Authorization': 'Basic ' + hash,
'Content-Type': 'application/json',
},
body: JSON.stringify({
template: { shortid: 'B1z8vSImQ' }
}),
// auth: {
// username,
// password
// }
}
requestify.request('https://gabrielsch.jsreportonline.net/api/report', options)
.then(response => {
})
.catch(error => console.log(error))
有谁知道可能会发生什么?我在任何地方都找不到这方面的任何资源。先感谢您
解决方案
你在做重复的JSON.stringify
。像这样删除它:
const options = {
method: 'POST',
headers: {
'Authorization': 'Basic ' + hash,
'Content-Type': 'application/json',
},
body: {
template: { shortid: 'B1z8vSImQ' }
}
}
推荐阅读
- sql - SQL:如果值可以为空,如何按值选择
- python - 你如何检查用户输入是否是别的东西?
- git - 如何确定 git pull 将下载多少数据?
- node.js - 简单的 Express JS API 令牌
- mysql - SQL "GROUP BY" 和 "INNER JOIN" 语句一起使用
- javascript - 导航栏引导程序 3 在引导程序 4 中不起作用
- woocommerce - WC_CREATE 未设置帐单或送货地址
- c# - 密码盐渍
- ios - swift - performSegue 在 RxSwift Observable 中不起作用
- python - 在python中解析网页时遇到错误