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. Advertising

  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. Advertising

  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. 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. =?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:
    591
    =?Utf-8?B?ZWpz?=
    Nov 9, 2004
  2. =?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,029
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  3. Matt
    Replies:
    1
    Views:
    4,048
    Bryce (Work)
    Apr 21, 2004
  4. Matt
    Replies:
    2
    Views:
    739
    GIMME
    Apr 24, 2004
  5. Replies:
    2
    Views:
    678
Loading...

Share This Page