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

0 votes

I'd want to pass the body parameters indicated in the screenshot.

image

I am using axios in my nodejs/express project . My request 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);
        });
};

How can I adequately pass the body parameters in this case?

Jun 14 in Node-js by Vaani
• 7,020 points
34 views

1 answer to this question.

0 votes
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
answered Jun 14 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
1 answer

How to get path from the request in nodejs?

Hello @kartik, Try this out: var http = require('http'); var ...READ MORE

answered Oct 14, 2020 in Node-js by Niroj
• 82,720 points
2,218 views
0 votes
1 answer

Making POST request to discord server in nodejs

You'll need to solve the captchas; I ...READ MORE

answered May 30 in Node-js by Vaani
• 7,020 points
15 views
0 votes
1 answer

How to process POST data in Node.js?

Hello @kartik, You can use the querystring module: var qs = ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,720 points
1,591 views
0 votes
1 answer

How to extract request http headers from a request using NodeJS connect?

Hello @kartik, To see a list of HTTP ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,720 points
13,560 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
966 views
0 votes
1 answer
0 votes
1 answer

Nodejs Instagram videos downloader not working

Firstly, Initialize a package.json file with default values. npm ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,560 points
21 views
0 votes
1 answer
0 votes
1 answer

How to use pino-transport in nodejs for logs?

Ensure that you have a recent version ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,560 points
39 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP