简体   繁体   English

通过HTTP进行JSON传输的可靠性如何?

[英]How reliable are JSON transfers over HTTP?

Are JSON responses ever incomplete because of server errors, or are they designed to fail loudly? JSON响应是否由于服务器错误而变得不完整,还是被设计为大声失败? Are there any special concerns for transferring very large sets of data over JSON, and can they be mitigated? 通过JSON传输非常大的数据集是否有任何特殊问题,可以缓解吗? I'm open to any suggestions. 我愿意接受任何建议。

Transferring JSON over HTTP is no different than transferring any bytes over HTTP. 通过HTTP传输JSON与通过HTTP传输任何字节没有什么不同。

Yes, server errors can result in incomplete transfers. 是的,服务器错误可能会导致传输不完整。 Imagine turning your server off half way through a transfer. 想象一下在传输过程中关闭服务器的过程。 This is true of any network transfer. 任何网络传输都是如此。 Your client will fail loudly if there is such an error. 如果出现此类错误,您的客户端将大声失败。 You might get a connection time out or an error status code. 您可能会得到连接超时或错误状态代码。 Either way you will know about it. 无论哪种方式,您都将知道。

There is no practical limit to the amount of data you can transfer as JSON over HTTP. 可以通过HTTP作为JSON传输的数据量没有实际限制。 I have transferred 1GB+ of JSON data in a single HTTP request. 我已经在一个HTTP请求中传输了1GB +的JSON数据。 When making a large transfer you want to be sure to use a streaming API on the server side. 进行大笔传输时,您要确保在服务器端使用流式API。 Which is to say write to the output stream of the HTTP response while reading the data from your db, rather than reading your data from the DB into RAM entirely and then encoding it to JSON and writing it to the output. 也就是说,在从数据库读取数据时写入HTTP响应的输出流,而不是将数据库中的数据完全读取到RAM中,然后将其编码为JSON并将其写入输出。 This way your client can start processing the response immediately, plus your server wont run out of memory. 这样,您的客户端可以立即开始处理响应,而且服务器不会耗尽内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM