Not able to send a fetch request after using Cloudflare's ssl

after using cloudflares ssl I can’t send a fetch request with https protocol. here is my code:

async function testRun() {

    console.log('testRun')

    const url = `https://www.google.com/recaptcha/api/siteverify?secret=some_secret_here&response=some_token_here`

    const httpsAgent = new https.Agent({
        rejectUnauthorized: false,
    });

    fetch(url, {
        method: 'post',
        agent: httpsAgent
    })
    .then(response => {

        console.log('response', response)
    })
    .then(google_response => {
        console.log('google_response', google_response)
    })
    .catch(error => console.log(error));

}

I get this error:

testRun
 response Response {
 size: 0,
timeout: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
disturbed: false,
error: null
},
[Symbol(Response internals)]: {
url: 'https://www.google.com/recaptcha/api/siteverify?secret=some_secret_here&response=some_token_here',
status: 404,
statusText: 'Not Found',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
}
google_response undefined

This is working with localhost and I think it may e a SSL or cors issue !

UPDATE: removing the agent from fetch options gives me another aspect of the error:

testRun
FetchError: request to https://www.google.com/recaptcha/api/siteverify failed, reason: Hostname/IP does not match certificate's altnames: Host: www.google.com. is not in the cert's altnames: DNS:amazeservice.net, DNS:www.amazeservice.net
 at ClientRequest.<anonymous> (/home/porsanes/application/node_modules/node-fetch/lib/index.js:1461:11)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
 at TLSSocket.emit (node:events:394:28)
 at emitErrorNT (node:internal/streams/destroy:157:8)
 at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
 type: 'system',
 errno: 'ERR_TLS_CERT_ALTNAME_INVALID',
 code: 'ERR_TLS_CERT_ALTNAME_INVALID'
}

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.