How to send a POST request?

Discussion in 'Python' started by kj, Jun 6, 2008.

  1. kj

    kj Guest

    Hi. Sorry for this very clueless question, but how does one write
    in Python an HTTP client that can send a POST request? The modules
    I've found (e.g. urllib, urllib2), as far as I can tell, seem to
    be limited to GET requests. (I could be wrong though; please
    correct me if this is so.)

    TIA!

    kynn

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
     
    kj, Jun 6, 2008
    #1
    1. Advertisements

  2. kj

    kj Guest

    In <g2cc24$638$> kj <> writes:

    >Hi. Sorry for this very clueless question, but how does one write
    >in Python an HTTP client that can send a POST request? The modules
    >I've found (e.g. urllib, urllib2), as far as I can tell, seem to
    >be limited to GET requests. (I could be wrong though; please
    >correct me if this is so.)


    Sorry, my mistake. I now see that urllib2 handles POSTs too.

    kynn

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
     
    kj, Jun 6, 2008
    #2
    1. Advertisements

  3. kj

    Jeff McNeil Guest

    The original urllib module will do it too, if you pass a data keyword
    argument to urllib.urlopen:

    u = urllib.urlopen('http://www.domain.com/cgi-bin/cgi.py',
    data=urllib.urlencode({'name': 'pythonguy'}))


    On Fri, Jun 6, 2008 at 6:04 PM, kj <> wrote:
    > In <g2cc24$638$> kj <> writes:
    >
    >>Hi. Sorry for this very clueless question, but how does one write
    >>in Python an HTTP client that can send a POST request? The modules
    >>I've found (e.g. urllib, urllib2), as far as I can tell, seem to
    >>be limited to GET requests. (I could be wrong though; please
    >>correct me if this is so.)

    >
    > Sorry, my mistake. I now see that urllib2 handles POSTs too.
    >
    > kynn
    >
    > --
    > NOTE: In my address everything before the first period is backwards;
    > and the last period, and everything after it, should be discarded.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Jeff McNeil, Jun 7, 2008
    #3
  4. kj

    subeen Guest

    On Jun 7, 6:17 am, "Jeff McNeil" <> wrote:
    > The original urllib module will do it too, if you pass a data keyword
    > argument to urllib.urlopen:
    >
    > u = urllib.urlopen('http://www.domain.com/cgi-bin/cgi.py',
    > data=urllib.urlencode({'name': 'pythonguy'}))
    >
    > On Fri, Jun 6, 2008 at 6:04 PM, kj <> wrote:
    > > In <g2cc24$> kj <> writes:

    >
    > >>Hi. Sorry for this very clueless question, but how does one write
    > >>in Python an HTTP client that can send a POST request? The modules
    > >>I've found (e.g. urllib, urllib2), as far as I can tell, seem to
    > >>be limited to GET requests. (I could be wrong though; please
    > >>correct me if this is so.)

    >
    > > Sorry, my mistake. I now see that urllib2 handles POSTs too.

    >
    > > kynn

    >
    > > --
    > > NOTE: In my address everything before the first period is backwards;
    > > and the last period, and everything after it, should be discarded.
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list


    check this link for http post:
    http://love-python.blogspot.com/2008/04/get-content-html-source-of-url-by-http.html

    regards,
    Subeen
     
    subeen, Jun 7, 2008
    #4
  5. kj

    kj Guest

    Thanks to Jeff and subeen for the helpful comments and suggestions.

    Kynn
    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
     
    kj, Jun 7, 2008
    #5
    1. Advertisements

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. Brian Birtle
    Replies:
    2
    Views:
    2,584
    John Saunders
    Oct 16, 2003
  2. =?Utf-8?B?ZXN3YW5zb24=?=

    asp.net form to send a request to a put request

    =?Utf-8?B?ZXN3YW5zb24=?=, Oct 29, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    805
    =?Utf-8?B?ZWpz?=
    Nov 9, 2004
  3. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,372
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  4. Nathan Sokalski
    Replies:
    3
    Views:
    2,173
    Larry Lard
    Nov 23, 2005
  5. Matt
    Replies:
    1
    Views:
    4,209
    Bryce (Work)
    Apr 21, 2004
  6. Matt
    Replies:
    2
    Views:
    841
    GIMME
    Apr 24, 2004
  7. Replies:
    2
    Views:
    831
  8. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    446
    Chris Reay
    Nov 4, 2003
Loading...