Some of the information here may be outdated, please check the book instead

Use the following to retrieve the raw POST data:

Reading the raw POST data can be useful in a number of scenarios. The raw POST data can be any data stream passed in as part of the HTTP POST request. For instance, say your server needs to receive an XML file from the caller. The caller can send an HTTP POST request to the server passing the XML as the raw POST data. The server-side script then reads the raw POST data and can do whatever is needed with the XML data.

Here is an example of a controller and view that receive XML as raw POST data then returns the same XML as proof of receiving the data. This is only a code sample illustrating the use of It does not perform additional steps that would commonly be found in a production system such as validating that the raw POST data is in fact XML or validating that the XML adheres to a particular schema.

# Controller code:
def index(): 
    response.headers['content-type'] = 'text/xml'
    xml =  # retrieve the raw POST data
    if len(xml) == 0:
        xml = '<?xml version="1.0" encoding="utf-8" ?><root>no post data</root>'
    return response.render(dict(xml=XML(xml)))

# View code:

Here is a sample call to the controller using CURL. This sample assumes the application name is "app" and that the controller is called "controller".

curl --data '<?xml version="1.0"><root>my xml data</root>'
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.