F
F
frostexzo2021-03-19 23:58:27
JavaScript
frostexzo, 2021-03-19 23:58:27

CORS error when sending request to CDEK API?

There is this code

const calcForm = document.querySelector('#compare-form');

const fetchData = () => {
  return {
    API_TOKEN: "HIDDEN",
    API_PASSWORD: "HIDDEN",
    
    data: {
      del_d2d: 0,
    },

    async sendRequest() {
      const response = await fetch(`https://api.cdek.ru/v2/orders?cdek_number=123 `, {
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Content-Type": "application/json",
        },
        method: "GET",
      });
    }
  }
}


When sending a request, we get a CORS error
60551006ce254561229077.png

Tell me what to do, I tried a lot of things, I don’t want to do anything, I know that I need to log in, but it’s the same with authorization, I just tried to send a GET to check the order, but it still won’t let me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadim Zakirov, 2021-03-20
@frostexzo

First, the "Access-Control-Allow-Origin": "*" header should send the CDEK, not YOU. Secondly, since he doesn’t give this header, then there’s nothing to be done - you won’t ask for information directly from the browser. You must contact your site (server), and your site must already make a request, receive data and send it to the browser - this is how it will work. In general, proxy the request through your server.

V
Vladimir, 2021-03-20
@Casufi

Does the CORS API itself support it?
sends Access-Control-Allow-Methods and Access-Control-Allow-Headers in response?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question