谷歌Appengine&jQuery:错误414(请求的URI太长)
问题描述:
我有问题发布数据到我本地的appengine应用程序使用JQuery Ajax。这里被简化客户端代码:谷歌Appengine&jQuery:错误414(请求的URI太长)
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太长)。我究竟做错了什么?
答
请勿使用GET将数据发送到服务器,请改用POST!虽然您使用的是POST,但通过请求参数提交数据,这些数据的大小有限。
尝试
text_to_save = 'large chunk of html here'
req = '/story/edit?story_id=' + story_id;
$.post(req, {data: text_to_save});
答
的URI的最大长度的限制。这很大,但是如果你传递一串长长的数据,你可能会击中它。重构您的代码以将文本作为后期变量发送。
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。
由于某些原因(错误或网站规则),我无法接受正确答案,所以谢谢。 – SM79 2010-09-16 12:21:20