简体   繁体   English

节点服务器无法处理通过axios get发送的数据,并返回与邮递员不同的错误

[英]Node server is unable to process data send with axios get and returns different error than postman

I am using node js server on my local environment, I have tested the APIs with postman and it is working as expected. 我在我的本地环境上使用node js服务器,我已经用邮递员测试了API,并且按预期工作。 Now I am working on creating front-end with the help on react js. 现在,我正在使用react js的帮助来创建前端。 I am having trouble with Axios.get method with parameters. 我在使用带有参数的Axios.get方法时遇到麻烦。 As it is not returning the same error as it does with postman. 因为它没有返回与邮递员相同的错误。 I am sending data in x-www-form-urlencoded in postman , and this is what i am trying to achieve with Axios in react js. 我正在邮递员中以x-www-form-urlencoded发送数据,这就是我试图在React js中使用Axios实现的目的。

let config = {
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            params: {
              eth_wallet: this.state.deposit_address
            },
          }
        axios.get(methods.verify_eth_transaction, config)
        .then((result)=>{
            console.log(result)
        })
        .catch((err)=>{
            console.log(err)
        })

I have also tried 我也尝试过

 axios.get(methods.verify_eth_transaction, qs.stringify(this.state.deposit_address), config)
        .then((result)=>{
            console.log(result)
        })
        .catch((err)=>{
            console.log(err)
        })

It should return "Unable to find a deposit. Please try again." 它应返回“找不到存款。请重试。” as it is in postman get call. 因为邮递员接到电话。 But it is returning "Wallet not found", making me believe that there is something wrong with the way i am sending parameters in my request. 但是它返回“找不到钱包”,使我相信我在请求中发送参数的方式有问题。

And this is how my node server use the parameters. 这就是我的节点服务器使用参数的方式。

Bridge.find({ eth_wallet: { $in: req.body.eth_wallet } }, (err, account) => {
//
//
})

Axios GET method doesnt take a body object. Axios GET方法不使用主体对象。 You can either change your API route to use POST method or you can change the way you are sending your params like this: 您可以更改API路由以使用POST方法,也可以更改发送参数的方式,如下所示:

axios.get(url, {
  params: {
    eth_wallet: this.state.deposit_address
  }
});

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM