470,648 Members | 1,518 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

can httplib.HTTPConnection use proxy?

how to use httplib.HTTPConnection with http proxy?

Mar 16 '06 #1
4 11360
JuHui wrote:
how to use httplib.HTTPConnection with http proxy?


simply connect to the proxy? - and ask using the full url and original
Host: - for HTTPS do a CONNECT <host>.

Robert
Mar 16 '06 #2
sorry, would you please give a sample code?
I want to use HTTPConnection to get a html page content via a http
proxy.
thanks.

Mar 16 '06 #3
>>> import httplib
h = httplib.HTTPConnection("www.google.ca")
h.connect() Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\lib\httplib.py", line 627, in connect
raise socket.error, msg
error: (10061, 'Connection refused') h2 = httplib.HTTPConnection("my.proxy.host", "my.proxy.port")
h2.connect()
h2.request("GET", "http://www.google.ca")
resp = h2.getresponse()
page = resp.read()


Mar 16 '06 #4
JuHui wrote:
sorry, would you please give a sample code?
I want to use HTTPConnection to get a html page content via a http
proxy.
thanks.


-> adam

and maybe you just want plain GET/POST. use urllib
url='http://www.google.ca'
urllib.FancyURLopener(proxies={'http':'http://vs:3128'}).open( url

).read()
'<html><head><meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1"><title>Google</title><style><!--\nbody,td,a,p,.h{font-family:arial,sans-serif;}\n.h{font-size:
20px....

Robert
Mar 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by scummer | last post: by
reply views Thread by Laszlo Zsolt Nagy | last post: by
2 posts views Thread by spamsink42 | last post: by
reply views Thread by JuHui | last post: by
5 posts views Thread by scott | last post: by
3 posts views Thread by Mark rainess | last post: by
reply views Thread by Dustin J. Mitchell | last post: by
3 posts views Thread by rhXX | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.