How to set up a https foward proxy for curl

允我心安 提交于 2021-01-29 08:11:28

问题


I am facing one problem, and not get solution on google

I try to use curl to visit a https website behind a proxy but fail.

It is success without proxy or visit without ssl. Then I deployed a tcp proxy (got from https://github.com/kklis/proxy), and set enviroment export https_proxy=127.0.0.1:443

visit https://www.baidu.com, I just got connection aborted error

Here is how I run proxy:

./proxy -l 8111 -h www.baidu.com -p 443

And set proxy environment:

export https_proxy=127.0.0.1:8111

Run curl:

curl -v https://www.baidu.com

Got result:

Rebuilt URL to: https://www.baidu.com/

Trying 127.0.0.1...

Connected to 127.0.0.1 (127.0.0.1) port 8111 (#0)

Establish HTTP proxy tunnel to www.baidu.com:443

CONNECT www.baidu.com:443 HTTP/1.1

Host: www.baidu.com:443

User-Agent: curl/7.47.0

Proxy-Connection: Keep-Alive

Proxy CONNECT aborted

Connection #0 to host 127.0.0.1 left intact

curl: (56) Proxy CONNECT aborted

I tried add --insecure and not work, same result.

I think this is the same issue some one has met, still no answer: https://github.com/h2non/balboa/issues/1

Thanks if anyone can help!


回答1:


I think I know the reason

I captured packets , using proxy to visit a https website , curl will start a HTTP CONNECT method to establish a tunnel. The tunnel should be between curl client and proxy, but TCP proxy will delivery all messages to web server, so web server will reset the connection.

A forward proxy should not just delivery messages between client and web server.It should understand the HTTP CONNECT method

I use a standard foward proxy - squid instead, then success.

Hope this helps



来源:https://stackoverflow.com/questions/53493932/how-to-set-up-a-https-foward-proxy-for-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!