Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Use Axios in React TS to send a post data

Goal:
Use Axios to send a post from client to backend by using React TS

Problem:
Axios code cannot send data to the backend while fetch code can make it.

The data, in relation, to axios will be id = 0 and firstname = null at backend

It works well when I use fetch code and I can see it at backend.

What part am I missing in order to send data as a post to backend in relation to axios?

Info:
*It doesn't work to use 'application/json'.
*It works when I use post man tool.
*The difference is Content-length and I tried to change number at axios post but it doesn't work.

Thank you!

enter image description here

enter image description here

const params = { 
  id: 1,
  firstName: "sdf"
}

var config = {
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded',
    'accept': '*/*' 
  },
  accept: { }
};

axios.post(AddClient, params, config)
.then(response => {
})
.catch(error => {
  console.log(error.response)}
);

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("id", "1");
urlencoded.append("firstName", "sdf");

let requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded
};

fetch("http://localhost:1122/api/v1/Test/AddClient", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!