API cs-cart put request by react and axios

427 Views Asked by At

I use react in front-end and cs-cart API in back-end. In the following code I used axios.put() as follows:

const data = JSON.stringify({
  "test1": "val1"
});

const config = {
  method: 'put',
  url: 'https://example.com/api/product/111',
  headers: {
    'Authorization': `Basic ${token}`,
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
  .then(res => {
    console.log(res)
  });

When sending a request, the browser sends a request with the OPTIONS method, which error: 405 Method Not Allowed returns. And the original request (PUT) is not sent.

cs-cart is installed on the server. And the react project on localhost

Options method detail

Request

1

There are 1 best solutions below

0
undefined On

Have you made sure to understand the error correctly i.e

The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response
status code indicates that the server knows the request method, but
the target resource doesnt support this method.

The server must generate an Allow header field in a 405 status code
response. The field must contain a list of methods that the target
resource currently supports.

Make sure that the server is able to understand how to interpret your request so the clients are able to proceed.

You can look at this in more detail below here.