xmlhttprequest - XMLHttpRequest 不接受表单数据中的 json.stingify
问题描述
我想知道我做错了什么,这适用于带有 formData 和 request 的浏览器,但它不适用于节点。我尝试运行以下代码并得到我将在下面提到的错误。
const HOST = 'http://myURL';
const request = new XMLHttpRequest();
const form = new FormData();
const data = {};
// build call to strapi
data['CustomFields'] = { "goes": "onOwn" };
form.append('data', JSON.stringify(data));
request.open('POST', `${HOST}/templates`);
request.setRequestHeader('authorization','Bearer tokenhere');
request.onload = function () {
if (request.readyState === request.DONE) {
if (request.status === 200) {
console.log(request.response);
console.log(request.responseText);
}
}
};
request.send(form);
我得到的错误是:
TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of FormData
在 form.append('data'... 我用 JSON.stringify 制作那个 JSON。
知道我做错了什么吗?
解决方案
推荐阅读
- javascript - NodeJS:产生子进程,并捕获孙进程的标准输出?
- python-3.x - 使用 BeautifulSoup 和请求解码网页
- elasticsearch - 将桶选择器或任何聚合后过滤(如在 sql 中)引入区域映射弹性搜索/kibana
- c++ - hpc 集群上的 libsnd 文件
- flutter - Flutter Provider 正在重绘但不清除最新的绘
- javascript - GraphQl 查询问题
- codeigniter - 会话变量未在 Codeigniter 4 中显示
- python - 将字符串张量转换为字符串列表
- android - Android:AtvRemoteProviderService 和 AOSP 固件
- netlogo - 主要和次要的 Netlogo 问题