简体   繁体   中英

How can I ignore SSL/TLS validation using the Fetch API?

I'm using the fetch API to download files from within an Electron render process. The server provides a self-signed certificate.

Electron throws the following exception:

电子异常

I do not want to turn of SSL/TLS entirely. Using process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; or setting the environment variable work, but this is completely insecure.

This is currently what I'm doing to fetch from the URL.

const requestInit: RequestInit = {
        credentials: "include",
        method: "GET"
    };
const response = await fetch(url, requestInit);

You'll find that SSL/TLS is the protocol required to make a request to the URL you pass. If it is an 'https://' url, then try removing the s to make an 'http://' request. If the service does not support an SSL/TLS free option, then you'll have to support their choice to require SSL/TLS.

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