简体   繁体   中英

How to pass text/plain content in axios POST request in nodejs

I want to pass body parameters as shown in screen shot 这里 ( in text/plain format )

I am using axios in my nodejs/express project . My reqeust format is as shown below:

var config = {
    headers: {
        'Content-Length': 0,
        'Content-Type': 'text/plain'
    }
};



const testInput = (req, res) => {
    axios.post('https://api.sandbox.xyz.com/v1/order/new', { firstName: 'Marlon' }, config)
        .then(function(response) {
            console.log('saved successfully')
        })
        .catch(function(error) {
            console.log(error);
        });
};

For this how can I pass the body parameters appropriately?

var config = {
    headers: {
        'Content-Length': 0,
        'Content-Type': 'text/plain'
    },
   responseType: 'text'
};
  1. responseType indicates the type of data that the server will respond with
  2. options are arraybuffer , blob , document, json , text, stream

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