请求头header的问题

阅读次数 137

body不变,第一次请求:

我的body========{"url":"https://jjjt.oss-cn-shanghai.aliyuncs.com/Office/contract/1688101897.docx","filename":"8332823567530503841.docx"} 我加密后的MD5值=========169463f3fe3633894ff7d041c8adf709 我接口中传的md5值===========169463f3fe3633894ff7d041c8adf709
返回的值==========={"code":30003,"message":"InvalidSignature","hint":"md5 not match. expect: 557a5e4d89e9cb625b81f9156f66dfb5bf266bbc, actual: c70a215282cb12224a46230c4f8cc3287862b511","extra":""}
我加密的和请求头中的值都是169463f3fe3633894ff7d041c8adf709,返回报错403,具体信息MD5不匹配,预期值为557a5e4d89e9cb625b81f9156f66dfb5bf266bbc,实际值为c70a215282cb12224a46230c4f8cc3287862b511.

body不变,第二次请求:

我的body========{"url":"https://jjjt.oss-cn-shanghai.aliyuncs.com/Office/contract/1688101897.docx","filename":"8332823567530503841.docx"} 我加密后的MD5值=========169463f3fe3633894ff7d041c8adf709 我接口中传的md5值===========557a5e4d89e9cb625b81f9156f66dfb5bf266bbc
返回的值==========={"code":30003,"message":"InvalidSignature","hint":"md5 not match. expect: 169463f3fe3633894ff7d041c8adf709, actual: 557a5e4d89e9cb625b81f9156f66dfb5bf266bbc","extra":""}
这次我请求头中放入的是第一次请求返回信息中的预期值,但是这次返回信息预期值变成了我加密后的169463f3fe3633894ff7d041c8adf709.

是我的加密方法少一步嘛?还是其他什么原因?

2 Answers

你好,第二次的 body 和 md5 是匹配的。可以确认下第一次的 body 跟第二次一样吗

String s = "{"url":"https://jjjt.oss-cn-shanghai.aliyuncs.com/Office/contract/1688101897.docx","filename":"8332823567530503841.docx"}"; MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, s);
body是写死的,不会变动,用的参数封装方法也是你们示例里的.

body 不变的情况下 Content-Md5 计算结果也不变的,您这边可以对比下前后代码差异

String rfc1123_3 = sdf3.format(new Date()); String s = "{"url":"https://jjjt.oss-cn-shanghai.aliyuncs.com/Office/contract/1688101897.docx","filename":"8332823567530503841.docx"}"; MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, s);
System.out.println("我的body========"+s);
String md5 = getMd5(s);
//sha1加密
String sha1 = getSha1(auth);
System.out.println("我接口中传的md5值==========="+md5);
try {
OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("https://solution.wps.cn/api/developer/v1/office/convert/to/png")
                .post(body)
                .addHeader("Date", rfc1123_3)
                .addHeader("Content-Md5", md5)
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "WPS-2:SX20230627EXRGPB:" + sha1)
                .build();

你好,请检查实际request发出后,Content-Type是否为application/json