[Vuejs]-Vuejs: axios; Passing custom header in POST method

0👍

The headers object should not be put into a "config" object.

It’s just…

axios({
    method: 'post',
    url: urltocall,
    {
        headers: {
            ....

0👍

Try doing it like this:

axios
    .post(urltocall, myDataAsJSON, {
      headers: {
        "Access-Control-Allow-Origin": "http://localhost:1337",
        "Accept": "application/json",
        "Content-Type": "application/json",
        "username": "test1"
      }
    })
    .then(response => {
      console.log("Success: " + response.data);
    })
    .catch(error => {
      console.log("Error: " + error.response.data);
    });

By the way, based on your 'Content-Type': 'application/json',, I know you’re trying to send a JSON object, but where/what is this object?

Also, refer to the Full documentation for more information.

Leave a comment