Google app engine 无法在应用程序引擎中读取post数据
我正试图以以下方式将数据发布到App Engine:Google app engine 无法在应用程序引擎中读取post数据,google-app-engine,python-2.7,Google App Engine,Python 2.7,我正试图以以下方式将数据发布到App Engine: sendMessage = function(path, data) { $.ajax({ type: "POST", url: path, data: data, contentType: "application/json", dataType: "json", failure: function(errMsg) {
sendMessage = function(path, data) {
$.ajax({
type: "POST",
url: path,
data: data,
contentType: "application/json",
dataType: "json",
failure: function(errMsg) {
alert(errMsg);
},
success: function(result,status,xhr){
alert(result);
}
});
};
sendMessage('/chatMessage', {"message": "aaaa"});
接收代码:
class ChatMessage(webapp2.RequestHandler):
def post(self):
user = users.get_current_user()
message = self.request.get("message", "fail")
logging.error('RequestBody:' + str(self.request.body))
logging.error('Message:' + message)
日志消息:
ERROR 2013-05-18 16:23:31,954 channels.py:52] RequestBody:message=aaaa
ERROR 2013-05-18 16:23:31,956 channels.py:53] Message:fail
INFO 2013-05-18 18:23:31,983 server.py:585] default: "POST /chatMessage HTTP/1.1" 200 2
显然,服务器上的消息是完整的,因为它说的是
message=aaaa
,但是为什么我不能从请求中“获取”消息呢?当发出POST请求时,您可以将数据编码到URL中,或者将数据放在请求正文中
request.get()
将获取url中的url编码参数
在您的情况下,您将数据放在请求主体中,因此一切都正常工作。如果需要数据,应该从请求主体解析数据