Node NPM Request how to send a post request

123 Views Asked by At

I have been googling for this and only found this.

    let req = request({
        url: "http://localhost/api/v1/phone",
        method: 'POST',
        json: {
            param1: "abc",
            param2: "def"
        }
    }, function callback(error, response, body) {});

This doesn't work. The error is:

client.js:771 POST http://localhost/[object%20Object] 400 (Bad Request)

How to fix this? This fails with the same eror if I change it to request.post.

    let req = request.post({
        url: 'http://localhost/api/v1/phone'

    }, (error, response, body) =>{
        logger.log('test123.error', error);
        logger.log('test123.response', response);
        logger.log('test123.body', body);
    });

but apparently it doesn't work.

0

There are 0 best solutions below