Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

node.js - How to use axios to make an https call?

I am trying to use axios with a proxy server to make an https call:

const url = "https://walmart.com/ip/50676589"
var config = { proxy: { host: proxy.ip, port: proxy.port } }

axios.get(url, config)
.then(result => {})
.catch(error => {console.log(error)})

The proxy servers I am using are all in the United States, highly anonymous, with support for HTTP and HTTPS.

I am receiving this error:

{ Error: write EPROTO 140736580649920:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794:

In order to ensure that the problem is with axios and NOT the proxy, I tried this:

curl -x 52.8.172.72:4444 -L 'https://www.walmart.com/ip/50676589'

This totally works just fine.

How do I configure axios to work with proxies and https URL's?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Axios https proxy support is borked if using https proxies. Try passing the proxy through [httpsProxyAgent][1] using http.

var axios = require('axios'); 

let httpsProxyAgent = require('https-proxy-agent');
var agent = new httpsProxyAgent('http://username:pass@myproxy:port');

var config = {
  url: 'https://google.com',
  httpsAgent: agent
}

axios.request(config).then((res) => console.log(res)).catch(err => console.log(err))

Alternatively there is a fork of Axios that incorporates this: axios-https-proxy-fix but I'd recommend the first method to ensure latest Axios changes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...