GET and POST

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • franck

    GET and POST

    HI,

    this is my code
    params = {}

    params['fuseaction'] = '*****';
    params['user'] = '***';
    params['password'] = '**********';
    params['num_card'] = '******';
    params['date_of_birth'] = '****';

    params = urllib.urlencod e(params)
    f = urllib.urlopen( "http://bidule.com",par ams)
    print f.read()

    my contact tell me i must do a GET or fuseaction and POST for other param.

    i dont know how to do this and if its possible.
    someone tell me its ok to do that, but how in python?

    i dont unsderstand the different between GET and POST but i know how to code
    it separately.

    thx in advance.



  • Jeremy Jones

    #2
    Re: GET and POST

    * franck (opo@opo.com) wrote:[color=blue]
    > HI,
    >
    > this is my code
    > params = {}
    >
    > params['fuseaction'] = '*****';
    > params['user'] = '***';
    > params['password'] = '**********';
    > params['num_card'] = '******';
    > params['date_of_birth'] = '****';
    >
    > params = urllib.urlencod e(params)
    > f = urllib.urlopen( "http://bidule.com",par ams)[/color]


    According to the urllib documentation (I've never used urllib, only
    httplib), all you have to do is change:

    f = urllib.urlopen( "http://bidule.com",par ams)
    to
    f = urllib.urlopen( "http://bidule.com?%s" % params)

    Here is the example from the documentation for a GET (found at

    [color=blue][color=green][color=darkred]
    >>> import urllib
    >>> params = urllib.urlencod e({'spam': 1, 'eggs': 2, 'bacon': 0})
    >>> f = urllib.urlopen( "http://www.musi-cal.com/cgi-bin/query?%s" % params)
    >>> print f.read()[/color][/color][/color]

    I haven't whether this works or not, so I take no responsibility for any
    damage caused by this code ;-)

    Jeremy Jones

    Comment

    • franck

      #3
      Re: GET and POST

      i know how to do a GET.
      :) i have this example.
      my contact tell my i must do a get AND a post :/

      GET to fuse param et POST for the others.

      dont know how do that.

      "Jeremy Jones" <zanesdad@bells outh.net> a écrit dans le message news:
      mailman.1063289 827.17272.pytho n-list@python.org...[color=blue]
      > * franck (opo@opo.com) wrote:[color=green]
      > > HI,
      > >
      > > this is my code
      > > params = {}
      > >
      > > params['fuseaction'] = '*****';
      > > params['user'] = '***';
      > > params['password'] = '**********';
      > > params['num_card'] = '******';
      > > params['date_of_birth'] = '****';
      > >
      > > params = urllib.urlencod e(params)
      > > f = urllib.urlopen( "http://bidule.com",par ams)[/color]
      >
      >
      > According to the urllib documentation (I've never used urllib, only
      > httplib), all you have to do is change:
      >
      > f = urllib.urlopen( "http://bidule.com",par ams)
      > to
      > f = urllib.urlopen( "http://bidule.com?%s" % params)
      >
      > Here is the example from the documentation for a GET (found at
      > http://www.python.org/doc/current/lib/node415.html):
      >[color=green][color=darkred]
      > >>> import urllib
      > >>> params = urllib.urlencod e({'spam': 1, 'eggs': 2, 'bacon': 0})
      > >>> f = urllib.urlopen( "http://www.musi-cal.com/cgi-bin/query?%s" %[/color][/color][/color]
      params)[color=blue][color=green][color=darkred]
      > >>> print f.read()[/color][/color]
      >
      > I haven't whether this works or not, so I take no responsibility for any
      > damage caused by this code ;-)
      >
      > Jeremy Jones
      >[/color]


      Comment

      • Brian Victor

        #4
        Re: GET and POST

        franck wrote:[color=blue]
        > i know how to do a GET.
        >:) i have this example.
        > my contact tell my i must do a get AND a post :/
        >
        > GET to fuse param et POST for the others.[/color]

        Without knowing urllib, I would infer from the rest of the code that
        you'd want to do something like this:

        getparams['fuseaction'] = '*****'
        postparams['num_card'] = '*****'

        getparams = urllib.urlencod e(getparams)
        postparams = urllib.urlencod e(postparams) # may not be necessary
        f = urllib.urlopen( "http://bidule.com?%s" % getparams, postparams)

        --
        Brian

        Comment

        • John J. Lee

          #5
          Re: GET and POST

          Brian Victor <bhv1@psu.edu > writes:
          [color=blue]
          > franck wrote:[color=green]
          > > i know how to do a GET.
          > >:) i have this example.
          > > my contact tell my i must do a get AND a post :/
          > >
          > > GET to fuse param et POST for the others.[/color]
          >
          > Without knowing urllib, I would infer from the rest of the code that
          > you'd want to do something like this:
          >
          > getparams['fuseaction'] = '*****'
          > postparams['num_card'] = '*****'
          >
          > getparams = urllib.urlencod e(getparams)
          > postparams = urllib.urlencod e(postparams) # may not be necessary
          > f = urllib.urlopen( "http://bidule.com?%s" % getparams, postparams)[/color]

          It seems unlikely that that's what is required (but you never
          know...).

          If the OP can post the HTML or a link, it would be rather easier to
          say what the problem is!


          John

          Comment

          • Steve Holden

            #6
            Re: GET and POST

            "franck" <opo@opo.com> wrote in message
            news:l908b.1425 $95.197@newsr2. u-net.net...[color=blue]
            > i know how to do a GET.
            > :) i have this example.
            > my contact tell my i must do a get AND a post :/
            >[/color]
            In which case your contact is likely talking through his or her hat. GET and
            POST are HTTP methods. In any given interaction the client can do either a
            GET or a POST (or one of a number of other methods: the operative word here
            is ONE).
            [color=blue]
            > GET to fuse param et POST for the others.
            >
            > dont know how do that.
            >[/color]
            I suspect what your contact means is that you have to provide the value of
            (I presume you mean) fuseaction encoded in the URL, and that the rest must
            be provided as POST data. This is a somewhat bizarre requirement (and their
            server is obviously not written in Python, but that's another thread ...).

            Try something like:

            params = {}

            params['user'] = '***';
            params['password'] = '**********';
            params['num_card'] = '******';
            params['date_of_birth'] = '****';

            params = urllib.urlencod e(params)
            f = urllib.urlopen( "http://bidule.com?fuse action=*****",p arams)
            print f.read()

            and see if that works. If not, go back to your contact for further
            enlightenment. Do they mean two operations or just one?

            regards
            --
            Steve Holden http://www.holdenweb.com/
            Python Web Programming http://pydish.holdenweb.com/pwp/



            Comment

            Working...