3

我正在使用 python 和谷歌应用引擎上的 webapp 框架开发一个简单的 RESTful web 服务。

基本上我通过 AJAX/jquery 发送所有请求 - 对于 POST 它就像一个魅力,但是当我用 PUT 发送数据时,参数是空的/未处理。

这是我的 PUT:

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

萤火虫说我说:

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

但使用这个python代码:

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"))

只会回来

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

所以..嗯,我在这里有什么遗漏吗?

干杯,马丁

4

1 回答 1

4

代码中的put方法被正确调用,因为如您所见,test已打印;不起作用的是参数解析,这个问题是课堂上的一个开放问题webob

您可以尝试解析 request.body 以提取查询字符串。

def put(self):
    print "test"
    name = parse_body_to_extract_your_parameter(self.request.body)
    self.response.out.write(name)
于 2010-12-26T22:41:57.260 回答