fetch() SSL disable certificate validation #44038
-
Hello, is there any way to disable SSL certificate validation for self-signed certificates or expired ones? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 24 replies
-
Yes, pass |
Beta Was this translation helpful? Give feedback.
-
use this in your fetch const https = require('https'); // or import https from 'https'
const agent = new https.Agent({
rejectUnauthorized: false,
});
fetch("https://google.com", { method: "get", body: body, agent }); |
Beta Was this translation helpful? Give feedback.
-
Obviously on localhost it's a matter of CORS |
Beta Was this translation helpful? Give feedback.
-
Using the built in fetch with undici, you can do import { Agent, setGlobalDispatcher } from 'undici'
const agent = new Agent({
connect: {
rejectUnauthorized: false
}
})
setGlobalDispatcher(agent)
await fetch('...') |
Beta Was this translation helpful? Give feedback.
-
For anyone looking to do this without dependencies, e.g. for scripting use: #!/usr/bin/env -S node --no-warnings
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
await fetch("https://localhost"); The lengths one has to go through with built-in |
Beta Was this translation helpful? Give feedback.
Using the built in fetch with undici, you can do