d3如何在邮件请求中正确传递请求正文? [英] d3 how to properly pass request body in a post request?
本文介绍了d3如何在邮件请求中正确传递请求正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个d3脚本,它根据返回的动态API发布请求的JSON结果生成一个表。
I have this d3 script that generates a table based on the returned JSON results of a post request to a dynamic API.
d3.request("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search")
.header("Content-Type", "application/json")
.post("intent=data-quality", function (error,data){
function tabulate(data, columns) {
var table = d3.select('#response').append('table')
var thead = table.append('thead')
var tbody = table.append('tbody');
// append the header row
thead.append('tr')
.selectAll('th')
.data(columns).enter()
.append('th')
.text(function (column) { return column; });
// create a row for each object in the data
var rows = tbody.selectAll('tr')
.data(data)
.enter()
.append('tr');
console.log(data)
// create a cell in each row for each column
var cells = rows.selectAll('td')
.data(function (row) {
return columns.map(function (column) {
return {column: column, value: row[column]};
});
})
.enter()
.append('td')
.text(function (d) { return d.value; });
return table;
}
// render the table
tabulate(data, d3.keys(data[0]));
});
当对API执行此发布请求时,这是预期通过输入参数的工作方式:
When executing this post request to the API this is how it is expected to work passed input parameter:
但是,当我是运行此脚本,我得到一个400错误代码返回。我想我知道我错过了哪些可能会通过请求正文?虽然不是100%肯定。任何帮助表示赞赏。
However when I'm running this script, I get a 400 error code returned. I think I know what I am missing which might be passing the request body? Not 100% certain though. Any help is appreciated.
推荐答案
看着你的 curl
,我的猜测是:
Looking at your curl
, my guess would be:
var data = {
"action": "string",
"fields": [
"string"
],
"filters": {}
};
d3.request("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search?intent=data-quality")
.header("Content-Type", "application/json")
.post(JSON.stringify(data), function (error,data) {
...
这篇关于d3如何在邮件请求中正确传递请求正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文