can httplib.HTTPConnection use proxy?

Discussion in 'Python' started by JuHui, Mar 16, 2006.

  1. JuHui

    JuHui Guest

    how to use httplib.HTTPConnection with http proxy?
    JuHui, Mar 16, 2006
    #1
    1. Advertising

  2. JuHui

    robert Guest

    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
    robert, Mar 16, 2006
    #2
    1. Advertising

  3. JuHui

    JuHui Guest

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

    adam Guest

    >>> 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()
    adam, Mar 16, 2006
    #4
  5. JuHui

    robert Guest

    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
    robert, Mar 17, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Molz
    Replies:
    3
    Views:
    3,562
    Darryl L. Pierce
    Sep 19, 2003
  2. Marko
    Replies:
    11
    Views:
    18,438
    Marko
    Oct 19, 2004
  3. deelan
    Replies:
    0
    Views:
    1,252
    deelan
    Apr 1, 2004
  4. Harel
    Replies:
    1
    Views:
    269
    Harel
    Jul 10, 2007
  5. Brian Raymond
    Replies:
    0
    Views:
    114
    Brian Raymond
    Apr 22, 2013
Loading...

Share This Page