Search code examples
frontendbackendrequest-headers

401 unauthorized error in requesting to backend


I am requesting to my backend APIs. but I have a problem.

when I request any post API, my response is this error. What is the problem and how can I solve it?

I am using axios for requesting and it's structure is this:

axios.post(url, form_data, { headers: { authorization: authorization, 'Access-Control-Allow-Origin':'*', } })

this is error

enter image description here


Solution

  • Can you show your backend code that validated your request token, Try using

    authorization: `Bearer ${token}`
    
    axios.post(url, form_data, {
      headers: {
        Authorization: `Bearer ${token}`,
        'Access-Control-Allow-Origin': '*',
      }
    });