[Tutor] Best way to POST XML to CGI
All, I have a Python program that makes images of data and I want to be able to make these via a web interface. I want to keep it simple so I thought I would send an XML file to a cgi program (XML is what I am supposed to use). I have the parsing of the XML all figured out but the way I am sending the XML and receiving it does not look like they are the best ways. I have an HTML form that I use to collect input on what kind of image. I then take that form input and make it into an XML string. I then take that XML string and POST it to a CGI script. I am using cgi to retrieve the XML string. Once I have the string I get the needed info and make an image. The Part that just does not look right to me is using form = cgi.FieldStorage() Of someone else wanted to just post an XML string they would have to have the same form name XMLhttp that is not very user friendly. My guess is I am missing something about how cgi can work. I bet Python has a simple way to receive a XML post so I do not have to look for a specific form name? Any help would be appreciated. Thanks, John Web page code to post XML in a text area form action=http:///cgi-bin/parsXML2.py; target=text/xml method=post TEXTAREA cols=60 name=XMLhttp rows=20 wrap=Real ?xml version=1.0 ? StatRequest requestID=user-20070531-Time /StatRequest /TEXTAREA INPUT type=submit value=Submit Query /FORM Code that receives the XML POST form = cgi.FieldStorage() if not (form.has_key(XMLhttp)): print content-type: text/html\n\n print H1Error/H1 else: xmlString = form[XMLhttp].value print content-type: text/html\n\n req = ParseXML() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best way to POST XML to CGI
Ertl, John C CIV 63134 [EMAIL PROTECTED] wrote I have a Python program that makes images of data and I want to be able to make these via a web interface. Fair enough. I want to keep it simple so I thought I would send an XML file to a cgi program But thats not simple. CGI is not really designed to deal with XML, they are almost complementary technologies. CGI sends name/value pairs either in GET or POST format. XML encodes the values into a text file. Different things. XML tends to be used for RPC or B2B type applications, CGI is typically used for basic form submissions. Sure you can do it, but I'm not sure there is much point! I'd probably look to use CGI to capture the details then create the XML file at the server end. Its a lot more efficient in terms of network bandwidth too. XML is about the most inefficient network protocol ever invented. I have an HTML form that I use to collect input on what kind of image. I then take that form input and make it into an XML string. I then take that XML string and POST it to a CGI script. As I say, a pretty complex process compared to a simple CGI submit action. I bet Python has a simple way to receive a XML post so I do not have to look for a specific form name? Python offers many ways to deal with XML file transmissions, including XML/RPC and SOAP. But CGI is probably not the best approach for XML IMHO. It can be done in the same way as posting a normal text file but its pretty much turning an easy job into a hard one for no benefit. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor