Javascript 将post中的json发送到服务器节点
这是我使用axios在post中发送就绪json的代码Javascript 将post中的json发送到服务器节点,javascript,node.js,rest,axios,Javascript,Node.js,Rest,Axios,这是我使用axios在post中发送就绪json的代码 const axios=require(“axios”); 常数jsonObj={ 序列号:“090982037439”,//字符串 传感器类型:'ciccio bello',//字符串 注册的价值单位:{ 值:30,//valore 度量单位:“摄氏度”///字符串 }, 值注册地址:'29-04-2021'///string }; const json=json.stringify(jsonObj); axios({ 方法:“post”
const axios=require(“axios”);
常数jsonObj={
序列号:“090982037439”,//字符串
传感器类型:'ciccio bello',//字符串
注册的价值单位:{
值:30,//valore
度量单位:“摄氏度”///字符串
},
值注册地址:'29-04-2021'///string
};
const json=json.stringify(jsonObj);
axios({
方法:“post”,
网址:'http://localhost:3000/api/post',
数据:json
});
但是我总是得到下面的错误(415)
常量选项={
标题:{'content-type':'application/json'}
};
轴心柱(
“/login”,
{
名字:“芬恩”,
姓:“威廉姆斯”
},
选择权
).catch((错误)=>{
console.log(错误)
});
415表示不支持的媒体类型
确保API端点支持json请求。祝你好运 您是否尝试过(假设这是用于web开发)在chrome开发工具中打开网络选项卡?
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise
rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11188) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.