1

I'm trying to use Axios in JS to send a post request with a Map object as data, but the receiving endpoint is getting an empty map. See code below:

let dataMap = new Map();
dataMap.set('testKey', 'testValue')
const article = { map: dataMap }

axios.post('http://localhost:3001/testEndpoint', article).then(data => {
    console.log(data['data']);
})
Nelson Matias
  • 453
  • 1
  • 4
  • 15
  • Try to set `{ map: JSON.stringify(dataMap) }` as body – lpizzinidev Nov 22 '21 at 17:23
  • Hi Luca, thank you for the response. I tried that and even though it works, since this was just some test data, when I tried using actual data, I noticed when I go over 93221 characters of the string, the testEndpoint doesn't even receive the request. I also tried setting maxContentLength and maxBodyLength to Infinity with no change – Nelson Matias Nov 22 '21 at 18:24
  • Have a look at this https://stackoverflow.com/a/56150320/3284355 – Molda Nov 22 '21 at 18:32
  • Thank you for the help, looking more into this I found Express has it's own limit of 100kb of data to receive. I made that infinity and it worked! – Nelson Matias Nov 22 '21 at 18:52

0 Answers0