views:

361

answers:

2

Newbie question...

I am using silverlight to POST data to my GAE application

  class XmlCrud(webapp.RequestHandler):
    def post(self):

      body = self.request.body

The data comes in fine but it is escaped like this:

%3C%3Fxml+version=%221.0%22+encoding%3D%22utf-16%22%3F%3E%0D%0A%3CBosses+xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22+xmlns%3Axsd

how do I unescape it?

A: 

I'd recommend not encoding it in the first place if the body of the post is just an XML document.

Hank Gay
Thanks, but then that leads to another question, how to POST from Silverlight without encoding (I am using WebClient)
Sam Mackrill
I'm not really up on .NET anymore, much less Silverlight, but will http://msdn.microsoft.com/en-us/library/system.net.webclient.uploadstringasync(VS.95).aspx do the trick?
Hank Gay
Thanks Hank that was what I was using, solution is to use WebRequest see full answer here http://stackoverflow.com/questions/664270/google-app-engine-on-silverlight/1119848#1119848
Sam Mackrill
+2  A: 

I agree with Hank.

The answer to your actual question, though, is that your example is URL encoded. To decode, replace each %XX with the character having hex value 0xXX, and + with space.

urllib.unquote_plus does this, and according to the docs it's in App Engine

urllib docs: http://www.python.org/doc/2.5.2/lib/module-urllib.html

Statement that urllib is supported (there may be others): http://code.google.com/appengine/docs/python/urlfetch/overview.html

Steve Jessop
Thanks!, I had looked at urllib briefly but assumed it could only do url decoding not HTML
Sam Mackrill