I';我正在尝试将JavaScript数据发送到我的NodeJS服务器

I';我正在尝试将JavaScript数据发送到我的NodeJS服务器,javascript,node.js,express,Javascript,Node.js,Express,因此,我试图通过POST请求将地理位置数据发送到NodeJS,但当我将数据记录到NodeJS代码中时,它只显示一个空对象 我已经和邮递员测试过了,我可以毫无问题地接收数据。我认为问题在于我的应用程序的客户端 //**This is in the client Side(pure JS); async function getWeather(position){ let coords ={ lat: position.coords.latitude, long: posit

因此,我试图通过POST请求将地理位置数据发送到NodeJS,但当我将数据记录到NodeJS代码中时,它只显示一个空对象

我已经和邮递员测试过了,我可以毫无问题地接收数据。我认为问题在于我的应用程序的客户端

//**This is in the client Side(pure JS);

async function getWeather(position){

  let coords ={
    lat: position.coords.latitude,
    long: position.coords.longitude
  }

  const options = {
    method: "POST",
    body: JSON.stringify(coords),
    headers: {
      "Content-Type": "aplication/json"
    }
  };

  let response = await fetch("http://localhost:3000/weather", options);
  let location = await response.json();
}


在客户端,您可以尝试此代码。您可以用端点替换url并尝试获取结果。如下所示,在执行脚本后,我将在
data
中返回响应

我希望这有帮助

(异步()=>{
const rawResponse=等待提取('https://httpbin.org/post', {
方法:“POST”,
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”
},
正文:JSON.stringify({lat:10,long:20})
});
const content=await rawResponse.json();
控制台日志(内容);

})();您需要提供一个。你的主体解析中间件在哪里?你有没有查看你的开发工具网络选项卡,看看你的POST请求主体中实际发送了什么?这将有助于确定错误发生的位置
//**This is in the server side

  app.post('/weather',(req,res)=>{

    let coords = req.body;
    console.log(coords); //This shows an empty object

    res.sendStatus(200);
  });