How do I send the body in a request (POST) on Xios?

Asked

Viewed 5,380 times

-2

    axios({
      method: 'post',
      url: 'https://backend.tangotechapp.com/REST/getTokenRequest',
      headers: { 'Content-Type': 'multipart/form-data' },

    }).then(
      response => {

        console.log(response.data);

      }
    ).catch(function (error) {
      console.log(error);
    });

  • But shows some error?

  • It does not return the token, the body is being sent empty.

  • The request type is 'Content-Type': 'Multipart/form-data'

1 answer

0

You can simply add "date" to the object. In this field you can add what you want to send along with the request. Example:

axios({
  method: 'post',
  url: '/user/12345',
  data: {
    nome: 'Victor',
    sobrenome: 'Nogueira'
  }
});

Read the documentation available on Github that might be useful: https://github.com/axios/axios

  • I have tried to do this, but it seems that nothing goes in the body, the token returns empty.

  • João take a look at your Api, because the call is correct, it’s supposed to work normally!

  • @Joãofilipe, The code above is right, so the error is probably in your api, but without the code it is hard to say.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.