REST API 响应中的校验和 [英] Checksums in REST API responses

查看:27
本文介绍了REST API 响应中的校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送带有响应内容的校验和是个好主意吗?如果是这样,计算校验和的最常用方法是什么?

Is it a good idea to send a checksum with the content of the response? And if so, what is the most common way to calculate the checksum?

示例:

HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json

22 
{test:1}

推荐答案

HTTP 的底层协议是 TCP,已经有校验和机制,所以我认为它没有用.

The underlying protocol for HTTP is TCP which already has a checksum mechanism, so I think it would be useless.

如果您仍然需要这种东西,您可以计算正文内容的 SHA1 签名,并将其作为自定义标头包含在您的响应中,例如

If you still need this kind of thing you could calculate a SHA1 signature of the body content and include it as a custom header in your response, something like

HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json
X-Checksum: 40325305549f7a09edb51ff8df9528ffd8434ac6

这篇关于REST API 响应中的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆