Node-fetch: Support of http proxy

Created on 16 Feb 2016  ·  4Comments  ·  Source: node-fetch/node-fetch

If I want to use http proxy,I will

 require('http').request({
    host:'127.0.0.1',
    port:8580,
    method:'POST',
    path:'https://www.google.com',
},function(res){
    //...
})

But I use node-fetch,

fetch(obj).then(function(res){
    ...
})

It throw TypeError: Parameter 'url' must be a string, not object

It does not support URL objects

Most helpful comment

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){
    ...
})

All 4 comments

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

see also: https://github.com/bitinn/node-fetch/issues/8#issuecomment-149125379

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){
    ...
})

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

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'.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

waldothedeveloper picture waldothedeveloper  ·  5Comments

teolag picture teolag  ·  5Comments

KamasamaK picture KamasamaK  ·  3Comments

wheresrhys picture wheresrhys  ·  3Comments

jimmywarting picture jimmywarting  ·  4Comments