GET and POST

F

franck

HI,

this is my code
params = {}

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

params = urllib.urlencode(params)
f = urllib.urlopen("http://bidule.com",params)
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.
 
J

Jeremy Jones

* franck ([email protected]) said:
HI,

this is my code
params = {}

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

params = urllib.urlencode(params)
f = urllib.urlopen("http://bidule.com",params)


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",params)
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):

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

Jeremy Jones
 
F

franck

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 said:
* franck ([email protected]) said:
HI,

this is my code
params = {}

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

params = urllib.urlencode(params)
f = urllib.urlopen("http://bidule.com",params)


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",params)
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):

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

Jeremy Jones
 
B

Brian Victor

franck said:
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.

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.urlencode(getparams)
postparams = urllib.urlencode(postparams) # may not be necessary
f = urllib.urlopen("http://bidule.com?%s" % getparams, postparams)
 
J

John J. Lee

Brian Victor said:
franck said:
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.

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.urlencode(getparams)
postparams = urllib.urlencode(postparams) # may not be necessary
f = urllib.urlopen("http://bidule.com?%s" % getparams, postparams)

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
 
S

Steve Holden

franck said:
i know how to do a GET.
:) i have this example.
my contact tell my i must do a get AND a post :/
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).
GET to fuse param et POST for the others.

dont know how do that.
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.urlencode(params)
f = urllib.urlopen("http://bidule.com?fuseaction=*****",params)
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top