java 我可以通过 HTTP 读取的响应大小是否有限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27309773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a limit of the size of response I can read over HTTP
提问by Kraken
I have a java program, that calls a url. The response of url is a json/string. I have to write a program that fetches the data from this url, but I was wondering if there's a limit on the max size HTTP can pass back?
我有一个调用 url 的 java 程序。url 的响应是一个 json/string。我必须编写一个程序来从这个 url 获取数据,但我想知道 HTTP 可以传回的最大大小是否有限制?
I was going to write my server side (url) in such a way that it fetches all the data from db, but if there's a limit on the size I can fetch from server, I can do the read in batches also?
我打算以这样一种方式编写我的服务器端(url),它可以从数据库中获取所有数据,但是如果我可以从服务器获取的大小有限制,我也可以批量读取吗?
So, is there a limit on the size of the response I can send over HTTP from server to my java program?
那么,我可以通过 HTTP 从服务器发送到我的 Java 程序的响应大小是否有限制?
Also, I came across this link.The last response talks about the size being equal to int, and I am not sure what that means. If someone can explain.
另外,我遇到了这个链接。最后一个响应谈到大小等于 int,我不确定这意味着什么。如果有人能解释一下。
Thanks
谢谢
回答by nablex
There is no technical limit to the size of a HTTP body.
HTTP 正文的大小没有技术限制。
In the link you refer to it seems a limit imposed by a specific object that parses the HTTP because the object uses an int for the size, this is of course possible but not related to the HTTP protocol.
在您引用的链接中,似乎是由解析 HTTP 的特定对象强加的限制,因为该对象使用 int 作为大小,这当然是可能的,但与 HTTP 协议无关。
In HTTP you always have to give a content-length to the other side (is both for request & response), if your response is really large, it is up to the client to process it in an acceptable way (e.g. stream it directly to a file backend).
在 HTTP 中,您始终必须向另一方提供内容长度(用于请求和响应),如果您的响应非常大,则由客户端以可接受的方式处理它(例如将其直接流式传输到文件后端)。
Chunking is nice but it is only meant for when you (the one sending the large response) don't know the actual total size of your response until you have streamed it. If you know the size beforehand, use the content-length header.
分块很好,但它仅适用于当您(发送大响应的人)在流式传输之前不知道响应的实际总大小时。如果您事先知道大小,请使用 content-length 标头。
回答by Munawwar Hussain Shelia
you can consume the response in chunks i.e if the response is 8 mb you can consume 1mb at a time
您可以分块使用响应,即如果响应为 8 mb,则一次可以使用 1mb
here is the example http://mrbool.com/keep-alive-connections-and-chunked-response-in-http-1-1-with-java/27915
这是示例 http://mrbool.com/keep-alive-connections-and-chunked-response-in-http-1-1-with-java/27915