B
B
be_a_man2020-07-02 01:16:57
Node.js
be_a_man, 2020-07-02 01:16:57

How to use https proxy in node.js?

const HttpsProxyAgent = require('https-proxy-agent')
const fetch = require('node-fetch')

const agent = new HttpsProxyAgent({
    protocol: 'https',
    host: '193.169.188.21',
    port: '5836'
})

fetch('https://jsonplaceholder.typicode.com/todos/1', { agent })
    .then(response => response.json())
    .then(json => console.log(json))


I get an error
UnhandledPromiseRejectionWarning: FetchError: request to https://jsonplaceholder.typicode.com/todos/1 failed, reason: write EPROTO 22644:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:


If the protocol is set to http it works. But I need https proxy

Why does python work but node doesn't?
import requests
import json

proxies = {
    'https': 'https://193.169.188.21':5836'
}

resp = requests.get('https://jsonplaceholder.typicode.com/todos/1', proxies=proxies)
print(resp.text)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dev-sasha, 2021-01-18
@dev-sasha

Maybe you should use the axios package?
NPM: https://www.npmjs.com/package/axios
GitHub: https://github.com/axios/axios
Proxy support is available.

A
Alexander Smirnov, 2021-05-22
@sasha-hohloma

I also encountered such a problem, the use of the socks protocol solved the problem. But I haven't been able to fix this error yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question