Answers for "POST request with body and headers, async-await"

0

POST request with body and headers, async-await

/**
 * Package that needed:
 * 'qs', 'axios' 
 * install by `npm install qs --save 
 */

// You can Add more to this 
let headers = {
	'content-type': 'application/x-www-form-urlencoded',
};

let body = {
    field1: 'foo',
    field2: 'bar',
};

// For async_await
let reponse = await axios({
	method: 'POST',
    headers: headers,
    data: qs.stringify(body), // <---- This step it is important
    url: `${YOUR_URL}`,
}); 


return response['data'];
Posted by: Guest on September-29-2021

Code answers related to "POST request with body and headers, async-await"

Code answers related to "Javascript"

Browse Popular Code Answers by Language