如何为curl设置https foward代理 [英] How to set up a https foward proxy for curl

查看:132
本文介绍了如何为curl设置https foward代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,没有在google上找到解决方法

我尝试使用curl访问代理后面的https网站,但失败.

没有代理或没有ssl的访问都是成功.然后,我部署了一个TCP代理(从 https://github.com/kklis/proxy 获得),并设置环境 export https_proxy = 127.0.0.1:443

访问 https://www.baidu.com ,我只是连接中止错误

这是我运行代理的方式:

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

并设置代理环境:

导出https_proxy = 127.0.0.1:8111

运行curl:

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

得到结果:

./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:

将URL重建为: https://www.baidu.com/

尝试127.0.0.1 ...

已连接到127.0.0.1(127.0.0.1)端口8111(#0)

建立到www.baidu.com的HTTP代理隧道:443

连接www.baidu.com:443 HTTP/1.1

主持人:www.baidu.com:443

用户代理:curl/7.47.0

代理连接:保持活动

代理CONNECT中止

与主机127.0.0.1的连接#0保持不变

curl:(56)代理CONNECT中止了

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.

我认为这与某些人遇到的问题相同,但仍然没有答案: https://github.com/h2non/balboa/issues/1

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

谢谢任何人的帮助!

推荐答案

我想我知道原因

我捕获了数据包,使用代理访问https网站,curl将启动HTTP CONNECT方法以建立隧道.隧道应该在curl客户端和代理之间,但是TCP代理会将所有消息传递到Web服务器,因此Web服务器将重置连接.

转发代理不应该只是在客户端和Web服务器之间传递消息,还应该了解HTTP CONNECT方法

我使用标准的前向代理-鱿鱼代替,然后成功.

希望这会有所帮助

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

这篇关于如何为curl设置https foward代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆