5

I am working on an application using React+Redux and using axios to make api calls.

Here's a sample call which fails:

axios.post(`${API_ROOT}${FIND_USER}${currentUserID}`, {
        headers: {
                'Authorization': token
        },
      })
    .then((response) => {
        console.log("Sucess")
    })

Request url when I see in network is something like:

http://domainName:8080/users/findUser/1234

API call fails at OPTIONS itself and error I am receiving from backend is

Response for preflight has invalid HTTP status code 403

It never reaches POST.

token is retrieved from localstorage and is something like Bearer eyJhbGci....

Backend developers are using Java and Spring .

Is there something wrong in the way I am calling the APIs or this problem should be resolved in the Backend?

This API works totally fine when tested through Postman.

FE_Addict
  • 647
  • 2
  • 11
  • 21
  • This is possibly a CORS issue, when you make a request via Postman, do you see any `Access-Control-Allow-Origin` headers in the response? – Dan Jun 25 '17 at 11:37

2 Answers2

1

Turns out there is already a solution for this problem in the backend :

How to configure CORS in a Spring Boot + Spring Security application?

It works like a charm !

FE_Addict
  • 647
  • 2
  • 11
  • 21
0

'headers' always come as 3rd parameter in POST request of axios. Give 2nd arguement if there is any or pass 2nd parameter as empty String.