Receiving xml via HTTP POST

455 views
Skip to first unread message

chefsmart

unread,
Nov 22, 2008, 12:06:33 PM11/22/08
to Django users
Hi All,

I am creating an Adobe AIR application that will interact with my
Django app. I am currently trying out django-rest-interface that can
be found on googlecode. However, there's too much behind-the-scenes
stuff django-rest-interface (for the little amount of knowledge I
have) and I need more control over the processing of both sent and
received data, thus I'm now doing it my own way.

I plan to create django views for: -
1. creating single or multiple new objects of each model (through xml
data received via HTTP POST),
2. retrieving single or multiple existing objects of each model
(retrieving via pk and retrieving all objects, paged). This single
object or multiple objects will be sent as xml when requested via HTTP
GET
3. updating single or multiple existing objects of each model (through
xml data received via HTTP POST)
4. deleting single or multiple existing objects of each model (through
xml data received via HTTP POST)

This is not REST, but it gives me the control I need.

Thus far I have item no. 2 above sorted out. I just can't figure out
how to receive xml data via HTTP POST. (I have only ever used HTTP
POST for html forms.) Let's say I have the following xml, how do I
send this xml data via HTTP POST?

<django-objects version="1.0">
<object pk="1" model="drf.state">
<field type="CharField" name="short_name">TX</field>
<field type="CharField" name="name">Texas</field>
<field type="BooleanField" name="is_active">1</field>
</object>
</django-objects>

All help is highly appreciated.

chefsmart

unread,
Nov 29, 2008, 8:25:56 PM11/29/08
to Django users
Can someone throw a few ideas at me regarding this please... I'm sure
seasoned Django-ists could have really good ideas about this...
Thanks.

On Nov 22, 10:06 pm, chefsmart <moran.cors...@gmail.com> wrote:
> Hi All,
>
> I am creating an Adobe AIR application that will interact with my
> Django app. I am currently trying out django-rest-interface that can
> be found on googlecode. However, there's too much behind-the-scenes
> stuff django-rest-interface (for the little amount of knowledge I
> have) and I need more control over the processing of both sent and
> received data, thus I'm now doing it my own way.
>
> I plan to create django views for: -
> 1. creating single or multiple new objects of each model (throughxml
> data received via HTTPPOST),
> 2. retrieving single or multiple existing objects of each model
> (retrieving via pk and retrieving all objects, paged). This single
> object or multiple objects will be sent asxmlwhen requested via HTTP
> GET
> 3. updating single or multiple existing objects of each model (throughxmldata received via HTTPPOST)
> 4. deleting single or multiple existing objects of each model (throughxmldata received via HTTPPOST)
>
> This is not REST, but it gives me the control I need.
>
> Thus far I have item no. 2 above sorted out. I just can't figure out
> how to receivexmldata via HTTPPOST. (I have only ever used HTTPPOSTfor html forms.) Let's say I have the followingxml, how do I

Daniel Roseman

unread,
Nov 30, 2008, 4:15:57 AM11/30/08
to Django users
No doubt someone will correct me if I'm wrong, but I don't think there
*is* any other way of receiving a file via POST except via a form. So
what you would need to do is simulate a form from your AIR app, with a
single field containing your XML data. Then you can simply process the
XML with your favourite Python XML library (personally I like
ElementTree) and create/update the objecst as required.

--
DR.

Malcolm Tredinnick

unread,
Nov 30, 2008, 7:48:41 PM11/30/08
to django...@googlegroups.com

On Sun, 2008-11-30 at 01:15 -0800, Daniel Roseman wrote:
[...]

> No doubt someone will correct me if I'm wrong, but I don't think there
> *is* any other way of receiving a file via POST except via a form.

You gave an answer, so it's going to look crabby to say this, but that
isn't correct. You can send anything in the body of an HTTP POST request
and Django will be able to work with it. What you cannot do is use
request.POST to access the data, since that does form-decoding. Instead,
use request.raw_post_data, which is the unprocessed input data (and
check request.METHOD to see which method was used to submit the data --
POST, PUT, etc).

Regards,
Malcolm


chefsmart

unread,
Dec 1, 2008, 11:54:23 AM12/1/08
to Django users
Daniel Roseman suggests a very simple and easy to implement solution.
Malcolm Tredinnick explained the usage of request.POST and
request.raw_post_data. I think I would like to keep it pure and go
towards implementing django views that will access and process
request.raw_post_data. The AIR app will do an HTTP POST that will
contain xml in the body of the message.

Just wondering, if this were to be done purely in django, how would
one go about doing a pure HTTP POST request through a django template?
Or am I confusing two tangentially separated ideas?

Regards.

On Dec 1, 5:48 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Daniel Roseman

unread,
Dec 1, 2008, 3:51:23 PM12/1/08
to Django users
On Dec 1, 12:48 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
No problem Malcolm - it's always good to be corrected. And I didn't
know about request.raw_post_data, so that's two things I've learned
today...
--
DR.
Reply all
Reply to author
Forward
0 new messages