|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
GET vs POST variables...
Hi,
I´m working on a new project with python as cgi. I´ve looking around trying to find out a way to distinguish GET variables from form submitted POST variables. For example: <form method=post action=process.py?a=1> <input type=text name=a> <input type=Submit name=Process> </form> In this case, I need to distinguish between the POST parameter which holds the name and the GET parameter which holds a 1. If I use: form = cgi.FieldStorage() then form["a"] will return a list and I´ll have no way of knowing which one is which... is that right? Although the sample is a little bit silly, and I could use different variable names, the reason I need this are a little bit more obscure. Greetings, Aliosha |
|
#2
|
||||
|
||||
|
You probably can't use the cgi module then and must do your own parsing of the environment variables.
On the other hand, mixing GET and POST variables is not such a good idea because it is nonstandard and some browsers apparently handle it badly. See http://www.perlmonks.org/index.pl?node_id=284816 http://www.perlmonks.org/index.pl?node_id=48840 Those two links are for perl, but it is the same principle really.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
The example you give does not make sense, since you can only pass parameters by either POST or GET, but not both at once. I think if you ran your example then the browser would either ignore the "?a=1" part of the URL, or give an error.
However you can tell how the parameters were passed by checking the 'REQUEST_METHOD' environment variable, which should be either 'GET' or 'POST'. (I think it can also be 'HEAD', but this is rarely used). e.g. Code:
import cgi import os if os.environ['REQUEST_METHOD'] == 'GET': print 'processing GET request' elif os.environ['REQUEST_METHOD'] == 'POST': print 'processing POST request' else: print 'unknown request type' Dave - The Developers' Coach |
|
#4
|
||||
|
||||
|
I solved this problem while i was writing my net module (which seems to come up alot lattly but) your welcome to the code if it helps you solve your problem or even just as an example!
http://forums.devshed.com/t129666/s.html&highlight=NET Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > GET vs POST variables... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|