سؤال

i'm working on a simple RESTful webservice with python with the webapp framework on the google app engine.

Basically i'm sending all request via AJAX/jquery - for POST it works like a charm, but when I'm sending data with PUT, the parameters are empty / not processed.

this is my PUT:

    $.ajax({
        type: "PUT",
        url: "/boxes",
        data: { name: this.name, archived: this.archived  },
        success: function(msg){
        }
    });

firebug saids i'm putting:

Parameter   application/x-www-form-urlencoded
archived    false
name    123112323asdasd

but using this python code:

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, template
from google.appengine.ext import db
from google.appengine.api.datastore_types import *
from django.utils import simplejson as json

import cgi
import datetime

class BoxHandler(webapp.RequestHandler):

def post(self): #working
    print "test"
    self.response.out.write(self.request.get("name"))

def put(self):
    print "test" #not working
    self.response.out.write(self.request.get("name"))

will just return

test
Status: 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0

so .. hm, is there anything i'm missing here?

cheers, Martin

هل كانت مفيدة؟

المحلول

The put method in your code is correctly invoked because as you can see, test is printed; what is not working is the parameter parsing, this problem is an open issue in the webob class.

You could try to parse the request.body to extract the query string.

def put(self):
    print "test"
    name = parse_body_to_extract_your_parameter(self.request.body)
    self.response.out.write(name)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top