Answer the question
In order to leave comments, you need to log in
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",
});
}
}
}
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question