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
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'.
Most helpful comment
It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent