cannot access POST content in Zope
Hello, I am trying to record the result of a POST request sent to Plone. I can get the content of the POST when I send the file post.xml (valid xml) curl http://elevator.sytes.net/RSR/setSMS -d @post.xml In this case, CONTENT_TYPE headers is set to 'application/x-www-form-urlencoded' by curl. but the content of the POST is empty when I do curl http://elevator.sytes.net/RSR/setSMS -H "Content-Type: text/xml" -d @post.xml I'm working on integrating SMS on Plone, and the external system sends me a text/xml header, text/xml is the right type, I think, according rfc 3023 I have been tracking the frames through tcpdump and the request looks good before zope. I have then parsed the code of Zope to find where I could change this, but I can't figure it out for the moment, and maybe it's something which need to be changed. Could you help me to fix this please? Best regards Manuel Spuhler www.rsr.ch Zope 2.9.7-final, python 2.4.4, Plone 2.5.3
--On 17. August 2007 01:52:27 +0200 Manuel Spuhler <manuel.spuhler@gmail.com> wrote:
Hello,
I am trying to record the result of a POST request sent to Plone.
I can get the content of the POST when I send the file post.xml (valid xml)
No idea where and how you look for the uploaded content. Everything in Zope is available from the REQUEST. And of course you can _not_ upload something to the mutator method of some object. This makes zero sense. You might write your script that takes the data from the REQUEST and calls the API method e.g. a mutator method. -aj P.S. Plone specific questions belong to the plone-users list
Hi Andreas, thank for your answer
No idea where and how you look for the uploaded content. Everything in Zope is available from the REQUEST. And of course you can _not_ upload something to the mutator method of some object. This makes zero sense. You might write your script that takes the data from the REQUEST and calls the API method e.g. a mutator method.
I think you misunderstood, curl send it in a form, content is not *uploaded* but encoded in a POST 'text/xml' and it's sent to a script from which which I look at request.RESPONSE.form, but it's empty when content-type is 'application/x-www-form-urlencoded' my problem is probably about content-type
P.S. Plone specific questions belong to the plone-users list
i think it is a Zope question, below the fact I'm using Plone Regards M.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Manuel Spuhler wrote:
Hi Andreas,
thank for your answer
No idea where and how you look for the uploaded content. Everything in Zope is available from the REQUEST. And of course you can _not_ upload something to the mutator method of some object. This makes zero sense. You might write your script that takes the data from the REQUEST and calls the API method e.g. a mutator method.
I think you misunderstood, curl send it in a form, content is not *uploaded* but encoded in a POST 'text/xml' and it's sent to a script from which which I look at request.RESPONSE.form, but it's empty when content-type is 'application/x-www-form-urlencoded' my problem is probably about content-type
If you are POSTing XML as the payload of your REQUEST, then the 'form' element *must* be empty: Zope's form marshalling doesn't know what to do with such a mess. You will need to parse REQUEST.body yourself, in such a case. Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGxctK+gerLs4ltQ4RAgnrAKC1SES5XJH93fJQKf9+zIKQNs+cpwCgpdJg hvaZBLycgNwUu8rsAMk2aFE= =sH90 -----END PGP SIGNATURE-----
On 8/17/07, Manuel Spuhler <manuel.spuhler@gmail.com> wrote:
but the content of the POST is empty when I do
curl http://elevator.sytes.net/RSR/setSMS -H "Content-Type: text/xml" -d @post.xml
I'm working on integrating SMS on Plone, and the external system sends me a text/xml header, text/xml is the right type, I think, according rfc 3023
I have been tracking the frames through tcpdump and the request looks good before zope.
Zope special-cases POST requests with content-type text/xml; it treats these as XML-RPC requests. I don't think you can work around this either. :( Take a look at HTTPRequest.processInputs in lib/python/HTTPRequest.py, together with lib/python/xmlrpc.py in your Zope installation, to see if you find a way around this, or where to patch to disable this. The easier way would for you to alter the format in which the SMS gateway contacts the Zope server, though. A properly encoded POST request (multipart/form-data) would be much preferable and easier to deal with than patching Zope ;). -- Martijn Pieters
Hello Martijn, many thanks for your answer
Zope special-cases POST requests with content-type text/xml; it treats these as XML-RPC requests. I don't think you can work around this either. :(
Ok, I see, this is bad for me :-/
Take a look at HTTPRequest.processInputs in lib/python/HTTPRequest.py, together with lib/python/xmlrpc.py in your Zope installation, to see if you find a way around this, or where to patch to disable this.
The easier way would for you to alter the format in which the SMS gateway contacts the Zope server, though. A properly encoded POST request (multipart/form-data) would be much preferable and easier to deal with than patching Zope ;).
I'll try the easiest way first, but as it's not standard, I might have to patch Zope in HTTPRequest.py I found # Hm, maybe it's an XML-RPC if (fs.headers.has_key('content-type') and 'text/xml' in fs.headers['content-type'] and method == 'POST'): # Ye haaa, XML-RPC! This could make my day ;-) Regards Manuel Spuhler
-- Martijn Pieters
Thank you Tres, if you have this problem, there is something in the Zope FAQ (!) http://wiki.zope.org/zope2/FAQ#i-want-to-post-xml-content-but-zope-assumes-a... For my Zope 2.9, the configure.zcml file would not work. At first sight the XmlFix could work for Zope 2.9, it didn't for me because I have SOAPSupport installed, which already patch ZPublisher.HTTPRequest So I patched ZPublisher.HTTPRequest again ## this is MS hack to disable xmlrpc and send back the text/xml # Hm, maybe it's an XML-RPC if (fs.headers.has_key('content-type') and 'text/xml' in fs.headers['content-type'] and method == 'POST'): form['xml']= fs.value self.maybe_webdav_client = 0 I had to add a "xml" key, because as Tres Seaver said, ( I just understood what you wrote when I dug into Zope, thank you for your help ) the xml body is not marshalled. Then I got my xml back in request.form['xml'] I'm not a Zope specialist, so it might sound terrible to do it like this. If you have a nice way to code it, I'd love to learn it. At last it works fine for me. Regards Manuel Spuhler www.rsr.ch
participants (4)
-
Andreas Jung -
Manuel Spuhler -
Martijn Pieters -
Tres Seaver