Нельзя делать запросы к локальным ресурсам (если cors?) и к файлам. Надо попробовать через CORS proxy: . По сути: бэкенд-серверу похер на корсы, это только фронту важно (что б нельзя было подделывать запросы от имени пользователя).
Example of POST request (JSON)
data = {}
fetch("https://example.com/" {
method: 'POST',
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *client
body: JSON.stringify(data) // body data type must match "Content-Type" header
})
Example of POST request (url encoded)
let data = {
email: 'test@gmail.com',
password: 'password'
};
fetch("https://server.net/login", {
method: 'POST',
mode: 'no-cors',
cache: 'no-cache',
body: new URLSearchParams(data),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
redirect: 'follow'
});
Change Referrer header
Этот скрипт сделает запрос с заголовком Referrer: https://origin.net/test:
history.pushState('', '', '/test');
let data = {
email: 'test@server.net'
};
fetch("https://server.net/change-email", {
method: 'POST',
referrerPolicy: 'unsafe-url',
body: new URLSearchParams(data),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
redirect: 'follow'
});