有没有办法通过 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 中的代理设置有关。不要在这些设置中设置代理,否则上面的代码将无法工作。
最佳答案
我尝试通过 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 Suite 代理一起工作得很好。
关于python - httplib 和 HTTPs 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12038213/