I have a frontend running on HTTPS locally with a local certificate. I'd like to hit a local backend that is on HTTP.
I added the meta tag to my index.html to allow for this:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
...but axios refuses to do it:
axios({
method: 'post',
baseURL: 'http://localhost:3000',
url: '/test',
data: {
firstName: 'Will',
lastName: 'Smith'
}
}).then((result) => {
console.log('done!');
}
Note that I explicitly add http to the baseUrl. Still, I get this:
POST https://localhost:3000/test net::ERR_SSL_PROTOCOL_ERROR
Axios still sends through https.
I tried using fetch:
fetch('http://localhost:3000/test', {
method : "POST",
body: JSON.stringify({
firstName: 'Finn',
lastName: 'Williams'
}),
}).then((response) => {
console.log('done! ' + response.json());
).catch((error) => {
console.log('error');
});
Then finally a raw XMLHttpRequest request:
const http = new XMLHttpRequest();
http.open("POST", 'http://localhost:3000/test', true);
// Call a function when the state
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(JSON.stringify({
firstName: 'Finn',
lastName: 'Williams'
}));
But every time the browser seems to switch to HTTPS and it fails with that same error.
Is it possible to make this happen?
//localhost:3000/testso withouthttp/httpsprefix, forcing the browser to decide?