httplib和HTTPs代理

2024-06-16 14:21:06 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法通过Fiddler的代理将用python的httplib发出的HTTPs请求隧道化,而不将Fiddler变成反向代理?

我尝试使用这个示例(来自here):

import httplib
c = httplib.HTTPSConnection('localhost',8118)
c.set_tunnel('twitter.com',443)
c.request('GET','/')
r1 = c.getresponse()
print r1.status,r1.reason
data1 = r1.read()
print len(data1)

但它又回来了:

<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><TITLE>Fiddler Echo Service</TITLE></HEAD><BODY STYLE="font-family: arial,sans-serif;"><H1>Fiddler Echo Service</H1><BR /><PRE>GET / HTTP/1.1
Host: localhost:8080
Accept-Encoding: identity

</PRE><BR><HR><UL><LI>To configure Fiddler as a reverse proxy instead of seeing this page, see <A HREF='http://fiddler2.com/r/?REVERSEPROXY'>Reverse Proxy Setup</A><LI>You can download the <a href="FiddlerRoot.cer">FiddlerRoot certificate</A></UL></BODY></HTML>

编辑: 这个代码有效。该问题与Internet Explorer中的代理设置有关。不要在这些设置中设置代理,否则上面的代码将不起作用。


Tags: echocomlocalhosthttp代理gettitlehtml
1条回答
网友
1楼 · 发布于 2024-06-16 14:21:06

我试过通过Burp代理使用urllib2(Proxy with urllib2),它成功了:

import urllib2
proxy = urllib2.ProxyHandler({'https': '127.0.0.1:8081'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
print urllib2.urlopen('https://www.google.com').read()

您的代码似乎与Burp套件代理一起工作得很好。

相关问题 更多 >