Node-fetch: Disable SSL verification

后端 未结 3 1956
北恋
北恋 2021-02-12 15:07

I have the following code, which is run from a express server:

import fetch from \'node-fetch\';

let formBody = [];

const dataLogin = {
      \'username\': \'         


        
3条回答
  •  日久生厌
    2021-02-12 15:47

    The other way to do is to set your own agent to the fetch call.

    const fetch = require('node-fetch');
    const https = require('https');
    
    const httpsAgent = new https.Agent({
          rejectUnauthorized: false,
        });
    
    const response = await fetch(url, {
          method: 'POST',
          headers: headers,
          body: body,
          agent: httpsAgent,
        });
    

提交回复
热议问题