简体   繁体   中英

NodeJS json provided in request is not sent with push

I am trying to call my api for a post webservice from a Node application. I successfully pulled data from this same api with a get method, so connexion works perfectly. Now I want to make a push

    request({
        method: 'POST',
        url: ws.url,
        json: {"id": 78, "product" : "MyProduct"}
    }, function (error, response,body) {
        console.log('error ',error);
        console.log('body ',body);
        console.log('response ',response);
        cb(error, response)
        //console.log(error, response)
    })

I ve got these console.log :

error  undefined
body  undefined
response  { errMsg: 'id not provided ' }

So the response is quite explicit, API havent received my id. However when I call manually same ws with Postman, it works normally.

So what s wrong with my json param? should I send it another way? My webservice needs to have this content in its body and nothing else:

{"id": 78, "product" : "MyProduct"}

I found my issue, and in fact the project where I am working extended Request library, and issue is in the method that overrode Request original behaviour. So to sum up, my code above is supposed to work, I just have to fix this dirty override.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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