New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of http proxy #79
Comments
You can pass a see also: #8 (comment) |
It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent
|
use https://github.com/zjael/simple-proxy-agent to support more proxy type. http、socks5. |
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')
})
|
You can use package tunnel to support node fetch with proxy. 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. |
If I want to use http proxy,I will
But I use node-fetch,
It throw
TypeError: Parameter 'url' must be a string, not object
It does not support URL objects
The text was updated successfully, but these errors were encountered: