How should I pass json data in the request payload of http post request

后端 未结 3 645
谎友^
谎友^ 2021-02-05 01:05

I wanted to know, how to pass the json request in the payload, for eg: {\'name\' : \'test\', \'value\' : \'test\'}:

var post_data = {};

var post_op         


        
3条回答
  •  青春惊慌失措
    2021-02-05 01:38

    i tried this and it seems to be working.I needed basic auth so i have included auth,if you don't need it you can discard it.

    var value = {email:"",name:""};
    
     var options = {
            url: 'http://localhost:8080/doc/',
            auth: {
                user: username,
                password: password
            },
            method :"POST",
            json : value,
    
        };
    
        request(options, function (err, res, body) {
            if (err) {
                console.dir(err)
                return
            }
            console.dir('headers', res.headers)
            console.dir('status code', res.statusCode)
            console.dir(body)
        });
    

提交回复
热议问题