Giter VIP home page Giter VIP logo

Comments (5)

jimliang avatar jimliang commented on May 22, 2024 88

It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent

fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')}).then(function(res){
    ...
})

from node-fetch.

jimliang avatar jimliang commented on May 22, 2024 4

use https://github.com/zjael/simple-proxy-agent to support more proxy type. http、socks5.

from node-fetch.

bitinn avatar bitinn commented on May 22, 2024 1

You can pass a http.Agent with custom proxy settings: https://github.com/bitinn/node-fetch#options

see also: #8 (comment)

from node-fetch.

lisonge avatar lisonge commented on May 22, 2024

It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent

fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')}).then(function(res){
    ...
})

i use typescript, and it type is incompatible

import { HttpProxyAgent } from 'http-proxy-agent';
import fetch from 'node-fetch';

fetch('', {
    method: 'GET',
    agent: new HttpProxyAgent('http://127.0.0.1:10809')
})

Type 'HttpProxyAgent' is not assignable to type 'Agent | ((parsedUrl: URL) => Agent) | undefined'. Property 'freeSockets' is missing in type 'HttpProxyAgent' but required in type 'Agent'.

from node-fetch.

kics223w1 avatar kics223w1 commented on May 22, 2024

You can use package tunnel to support node fetch with proxy.
Example Implement:

   const tunnel = require('tunnel');  
   const fetch = require('node-fetch');
   import fs from 'fs';
  
    const configTunnel = {
      ca: [fs.readFileSync(
      "YOUR_CERTIFICATE_PATH"
    )],
      proxy: {
        host: this.currentIP,
        port: proxyPort,
      },
    };

    const tunnelHTTPS = tunnel.httpsOverHttp(configTunnel);

    const tunnelHTTP = tunnel.httpOverHttp(configTunnel);

    let config: Record<string, any> = {
      url: flow.request.url,
      method: method,
      headers: headers,
      agent: flow.isSSL ? tunnelHTTPS : tunnelHTTP,
    };
    if (flow.request.bodySize > 0 && method !== 'GET' && method !== 'HEAD') {
      config.body = flow.request.body;
    }

   try {
      const response = await fetch(flow.request.url, config);
    } catch (e: any) {
      throw new Error(e.message);
    }

Note that: node fetch with proxy doesn't work if Method GET contains body.

from node-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.