简体   繁体   中英

axios 403 forbidden on OPTIONS request

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.

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 !

'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM