尝试通过多种方式询问后检查表格。
我正在尝试使用 .gz 文件上传请求正文来发送发布请求。 尝试使用多部分表单数据, 收到 400 错误请求作为响应。
还尝试将其作为二进制文件加载为.body(gzfile) - 同样的错误
尝试了很多方法,无法确定我缺少什么。 使用最新的 Rest Assured 依赖项 5.5.0。
任何建议 解决方案可以提供帮助。
请忽略不记名令牌的差异,已对其进行编辑使其看起来很短
我的 Swagger 响应 Curl
curl -X 'POST' \
'https://32.039.1.471:8299/testingapi/abc' \
-H 'accept: application/json' \
-H 'Accept-Encoding: application/gzip' \
-H 'multipart-form-data: multipart/form-data' \
-H 'Host: Default Host' \
-H 'Initiator-User-Id: TESTING' \
-H 'Initiator-Location: IN' \
-H 'Initiator-Entity-Id: ABCD' \
-H 'Servicing-Channel-Id: Swagger'
-H 'Servicing-Application-Id: TESTING' \
-H 'Servicing-Entity-Id: ABCD' \
-H 'Target-Entity-Id: ABCD' \
-H 'SSAM-Application-Id: TESTING' \
-H 'Correlation-Request-Id: 12345'
-H 'Authorization: Bearer eyJhbGcioiJkaXIiLCJlbmмioiJBMjU2QØJDLUHTNTEyIiwidHlwIjoislduIiwiY3R51joislduino.' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=application/x-gzip'
Request URL
https://32.039.1.471:8299/testingapi/abc
我的放心码
token = "Bearer eyJhbGcioiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUHTN";
File gzFile new File(System.getProperty("user.dir")+"/abcDataUpdated.json.gz");
RestAssured.useRelaxedHTTPSValidation();
Response response = given()
.log().all()
.when()
.header("accept", "application/json")
.header("Accept-Encoding", "application/gzip")
.header("multipart-form-data","multipart/form-data")
.header("Host", "Default Host") .header("Initiator-User-Id","TESTING")
.header("Initiator-Location","IN")
.header("Initiator-Entity-Id", "ABCD")
.header("Servicing-Channel-Id", "Swagger")
.header("Servicing-Application-Id","TESTING")
.header("Servicing-Entity-Id","ABCD") .header("Target-Entity-Id","ABCD")
.header("SSAM-Application-Id","TESTING")
.header("Correlation-Request-Id","123456")
.header("Authorization", token)
.header("Content-Type", "multipart/form-data") .body (gzFile)
.multiPart("File", gzFile, "application/x-gzip")
//.contentType (ContentType.MULTIPART)
.post("https://32.039.1.471:8299/testingapi/abc")
.then()
.log().all()
.extract().response();
Intellij Run 控制台中的我的响应日志详细信息,
Headers:
accept-application/json
Accept-Encoding=application/gzip
Host=Default Host
Initiator-User-Id-TESTING
Initiator-Location=IN
Initiator-Entity-Id-ABCD
Servicing-Channel-Id=Swagger
Servicing-Application-Id=TESTING
Servicing-Entity-Id=ABCD
Target-Entity-Id=ABCD
SSAM-Application-Id=TESTING
Correlation-Request-Id=123456
Authorization=Bearer eyJhbGci0iJkaXIiLCJlbmMiOiJBMjU2Q0JDLUHTNTEyIiwidHlwIjoisldUIiwiY3R5Ijois
Cookies:
<none>
Content-Type-multipart/form-data
`Multiparts:
Content-Disposition: form-data; name = File; filename = abcDataUpdated.json.gz
Content-Type: application/x-gzip`
我的回复状态和通过上述代码收到的消息
400 错误请求 - 请求格式错误
在 Swagger 中,文件上传部分位于请求正文中,
File (Choose File upload Button)
string($binary)
解决了问题, 这是 API 端接受编码的问题, .header("接受编码", "应用程序/gzip")
它必须是 gzip、deflate,而不是 application/gzip。
管理员,请关闭此帖子!