[Vuejs]-VueJs axios unauthorized POST request with Authorization header

0๐Ÿ‘

โœ…

My issue was that the header was being sent as an object in request body and not as a header.

Fixed the issue using this code:

      axios
    .request({
      url: "api/listings",
      method: "POST",
      headers: {
        Authorization: "Bearer " + this.token,
      },
      data:{
      ListingName: this.name
      }

    })
    .then((response) => {
      console.log(response);
    });
}

Leave a comment