- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用基于 Java 的 Azure 函数计算通过 POST 请求提交的文件的 md5 校验和。但是,当我将文件作为字符串作为请求的一部分提交时,它包含一些不断变化的 header 信息(不确定为什么),因此 md5 校验和随着每个请求不断变化。
public class Function {
/**
* This function listens at endpoint "/api/HttpExample". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpExample
* 2. curl "{your host}/api/HttpExample?name=HTTP%20Query"
* @throws IOException
*/
@FunctionName("HttpExample")
public HttpResponseMessage run(
@HttpTrigger(
name = "req",
methods = {HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) throws IOException {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
final String content = request.getBody().get();
context.getLogger().info(content);
byte[] md5Bytes = DigestUtils.md5(content);
String md5 = Base64.getEncoder().encodeToString(md5Bytes);
if (md5 == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body(md5).build();
}
}
}
下面是上面的日志记录语句针对两个不同请求(针对同一 tmp.txt 文件)的输出:
[2022-01-25T11:25:50.663Z] ----------------------------657892529889811456400753
[2022-01-25T11:25:50.664Z] Content-Disposition: form-data; name="file"; filename="tmp.txt"
[2022-01-25T11:25:50.664Z] Content-Type: text/plain
[2022-01-25T11:25:50.665Z]
[2022-01-25T11:25:50.665Z] abd
[2022-01-25T11:25:50.666Z] ----------------------------657892529889811456400753--
和
[2022-01-25T11:26:05.836Z] ----------------------------005234239999372220970885
[2022-01-25T11:26:05.837Z] Content-Disposition: form-data; name="file"; filename="tmp.txt"
[2022-01-25T11:26:05.838Z] Content-Type: text/plain
[2022-01-25T11:26:05.838Z]
[2022-01-25T11:26:05.838Z] abd
[2022-01-25T11:26:05.839Z] ----------------------------005234239999372220970885--
由于 header 不同,生成的 md5 校验和也不匹配。有没有一种聪明的方法来只删除内容?
任何帮助将不胜感激。
最佳答案
我找到了问题的解决方案:我从 Azure 逻辑应用调用该函数。因此,首先转换为字符串,然后将此字符串传递给函数应用程序就可以了:
byte[] b = File.ReadAllBytes(@"filepath");
string s = Convert.ToBase64String(b);
关于java - Azure函数计算md5校验和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70847977/
如何在 PHP 中生成 CRC-8 校验和? 最佳答案 function crcnifull ($dato, $byte) { static $PolyFull=0x8c; for ($i=0
我正在编写代码来使用 32 位无符号整数计算 CRC16。当尝试打印执行 CRC 操作的 XOR 函数的返回值时,它总是打印 0。我尝试了各种调试方法,例如打印语句,但是,我似乎无法弄清楚! 这是我的
ThinkPHP3.2.3验证码显示、刷新、校验 ,具体如下: 显示验证码 首先在Home/Controller下创建一个公共控制器PublicController
我想将自定义验证绑定(bind)到 TimePicker 自定义控件,但下面的代码显示“无法将内容添加到 TimePicker 的对象类型。”。
目录 Spring 校验(validator,JSR-303)实现 什么是JSR-303规范 与Spring MVC结合 实体类添加
导包和配置 导入 JSR 303 的包、hibernate valid 的包 ?
我是一名优秀的程序员,十分优秀!