Grails JSON 最大长度

发布于 2024-12-04 14:35:20 字数 725 浏览 0 评论 0原文

我知道 JSON 字符串通常在 PHP 上的 Apache 中定义最大长度,但是使用 TomCat 在 Grails 中定义的 JSON 字符串的最大长度在哪里?

我发送的 JSON 字符串长度为 13,636 个字符,但是我可以将其缩短很多(尽管我们在测试时我不想这样做) - 而且,我们将来可能会通过 JSON 发送图像,我已经读取需要 Base64 编码,因此需要相当大的开销。如果我们要做这样的事情,那么我担心如果这个限制导致了问题,那么我们现在就应该克服它。

如果没有限制,那么也许我做错了什么。我有有限数量的域对象,我使用 domainInstance as grails.converters.deep.JSON 将其编码为 JSON - 这是使用 for 循环完成的,并且每次JSON 字符串附加到 StringBuilder

然后我使用 render(stringBuilder.toString()) 在视图中渲染 StringBuilder,第一个 JSON 字符串很好,但第二个是接近尾部时被截断。如果我要估计的话,我会说我得到了 StringBuilder 总长度的 80% 左右。

编辑/解决方案:抱歉,伙计们&女孩们,我注意到,当我在页面上查看源代码时,我得到了完整的 JSON 字符串,但是当我只查看页面时,它被截断了。这是一个奇怪的错误,不过我会接受关于为什么它被截断的答案。谢谢。

I am aware that JSON strings often have a max length defined in either Apache on PHP, however where is the max length for JSON strings defined in Grails using TomCat?

The JSON string I am sending is 13,636 characters in length, however I can shorten it a lot (although I don't want to while we're testing) - also, we may be sending images via JSON in the future which I've read requires base64 encoding and thus a considerable overhead. If we were to do such a thing then I am worried that if this limit is causing problems, it's something we should overcome now.

If there is no limit, then perhaps I am doing something wrong. I have a finite amount of domain objects that I am encoding as JSON using domainInstance as grails.converters.deep.JSON - this is done using a for loop and each time the JSON string is appended to a StringBuilder

I then render the StringBuilder in a view using render(stringBuilder.toString()) and the first JSON string is fine, however the second is truncated near to the end. If I were to guestimate I'd say I am getting around 80% of the total length of the StringBuilder.

EDIT/SOLUTION: Apologies guys & girls, I've noticed that when I view source on the page I get the complete JSON string, however when I just view the page it's truncated. It's an odd error, I'll accept answers on why it's truncated, though. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨轻弹 2024-12-11 14:35:20

Tomcat 中的 POST 请求有一个最大大小,如果您开始发送巨大的 JSON/Base64 图像请求(就像您提到的那样),稍后您可能会担心这个问题。

tomcat 中的默认值为 2,097,152 字节 (2 MB);可以通过在 server.xml 中设置 maxPostSize 属性来更改它。

来自文档(对于 maxPostSize在 Tomcat 7 中):

将由 POST 处理的最大大小(以字节为单位)
容器FORM URL参数解析。该限制可以通过以下方式禁用
将此属性设置为小于或等于 0 的值。如果不是
如果指定,此属性设置为 2097152(2 兆字节)。

如果您要将 Grails war 部署到独立的 Tomcat 实例,那么配置起来非常简单。但是,如果您使用 tomcat 插件。如果是我,我可能会使用 war 而不是 grails run-app 来运行大文件测试。

There is a maximum size in Tomcat for POST requests, which you may be concerned with later if you start sending huge JSON / Base64 image requests (like you mentioned).

The default value in tomcat is 2,097,152 bytes (2 MB); it can be changed by setting the maxPostSize attribute of the <Connector> in server.xml.

From the docs (for maxPostSize in Tomcat 7):

The maximum size in bytes of the POST which will be handled by the
container FORM URL parameter parsing. The limit can be disabled by
setting this attribute to a value less than or equal to 0. If not
specified, this attribute is set to 2097152 (2 megabytes).

This is pretty straightforward to configure if you're deploying a Grails war to a standalone Tomcat instance. However, I can't find much about actually configuring server.xml if you're using the tomcat plugin. If it were me, I'd probably just run large-file tests using the war instead of with grails run-app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文