javascript帖子请求发送一个空的身体

时间:2017-10-23 18:30:07

标签: javascript post fetch

所以我有两个帖子请求一个注册一个完全正常,一个登录一个连接到服务器,但它发送一个空体。我已经编码了几个小时,所以这可能很容易成为一个简单的错误,但我没有看到它。任何帮助将不胜感激。

这是代码:

class Auth{

  signUp(user){
    return(

        fetch(`http://localhost:3001/signup`,
          {  headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
                },
            method: "POST",
            body: JSON.stringify(user,null,2)
            }).then((res)=>{
              console.log(res)
            }).catch((error)=>{
              console.log(error)
            })

        )
    }

  login(email,password){

    console.log(JSON.stringify({email:email,password:password},null,2))



      return(

            fetch(`http://localhost:3001/login`,
              { header:{
                'Accept': 'application/json',
                'Content-Type': 'application/json'
              },

              method:"POST",
              body: JSON.stringify({email:email,password:password},null,2)

            }).then((res)=>{
                console.log(res)
            }).catch((error)=>{
              console.log(error)
            })

        )

    }


}


export default Auth;

server.js

    app.post('/signup',function(req,res){
  console.log(req.body)
  myDietApi.createUser(req.body)
  .then((data)=>{
    res.send(data)
  }).catch((error)=>{
    console.log(error)
  })
})

app.get('/signup',function(req,res){
  myDietApi.getItemList()
  .then((list)=>{
    res.send(list)
  })

})

app.post('/login',function(req,res){
  console.log(req,'line 39')
  myDietApi.requestLogin(req.body)
   .then((user)=>{
    console.log('succes',user)
    res.send(user)
  })
})

这是服务器代码

0 个答案:

没有答案
相关问题