Skip to content
Advertisement

Axios change http to https

I have server that accept only http (no https). And when I call an api, axios automatically change http to https.

I create axios instance here:

export const axiosAgent = axios.create({
    baseURL: "http://xxx.xxx.xxx/api/v1/",
});

But in browser http changes to https, so it become: https://xxx.xxx.xxx/api/v1/all

and I get net::ERR_NAME_NOT_RESOLVED

How can I prevent that?

UPDATE Request Header:

Provisional headers are shown
Accept: application/json, text/plain, */*
Access-Control-Allow-Origin: *
Referer: http://localhost:3000/patients
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36

and there is no response header.

and now I get net::ERR_SSL_PROTOCOL_ERROR

Advertisement

Answer

I just remove <meta http-equiv="Content-Security-Policy" content="default-src 'self'"> from head in html. and problem solved. This meta tag change all http request to https one, so this is not related to axios.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement