Google Appengine& jQuery:错误414(请求的URI太长)

时间:2010-09-16 12:02:14

标签: jquery google-app-engine post

我在使用JQuery Ajax将数据发布到本地appengine应用程序时遇到问题。这是简化的客户端代码:

text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id + '&data=' + text_to_save;
$.post(req, function(data) {
    $('.result').html(data);
});

这是简化的服务器端代码:

class StoryEdit(webapp.RequestHandler):
    def post(self):
        f = Story.get(self.request.get('story_id'))
        f.html = self.request.get('data')
        f.put()

错误是414(请求的URI太长)。我做错了什么?

2 个答案:

答案 0 :(得分:6)

不要使用GET将数据发送到服务器,而是使用POST!虽然您使用的是POST,但数据是通过Request-Parameters提交的,但这些数据的大小有限。

尝试

text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id;
$.post(req, {data: text_to_save});

答案 1 :(得分:3)

URI具有最大长度限制。它很大,但是如果你传递了一长串数据,你可能会遇到它。重构代码以将文本作为post变量发送。

text_to_save = 'large chunk of html here'
req = '/story/edit';
$.post(req, { story:id: story_id, data: text_to_save }, function(data) {
    $('.result').html(data);
});

class StoryEdit(webapp.RequestHandler):
    def post(self):
        f = Story.get(self.request.post('story_id'))
        f.html = self.request.post('data')
        f.put()

以下是一些更多信息:“通常,Web服务器对真正的URL设置了相当大的限制,例如最多2048或4096个字符” - http://www.checkupdown.com/status/E414.html