简体   繁体   中英

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

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.

In my case, I had the extension "HTTPS Everywhere" and that caused the redirection. Please check if you have any such extensions installed.

If Yes, disable the extension for time being.

You can set url param with protocol. Example:

axios({
  method: 'GET',
  url: 'http://localhost:5050'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM