java+ retasted remove content-transfer-编码:来自Multipart请求的二进制文件

发布于 2025-02-13 15:40:59 字数 1113 浏览 1 评论 0原文

我目前正在测试一个非常具体的API,该API拒绝接受具有内容转移编码的请求:二进制。我抛出415-不支持的媒体类型错误。但是,当我发送相同的文件并使用Postman构建相同的请求时,它会毫无问题地接受它。查看服务中收到的内容的日志,这两个请求中的唯一区别是,已重新安排的一个内容具有内容传输编码:体内的二进制。它的外观是:

“在此处输入图像描述”

因此,为了调试和查明,是否确实是请求失败的原因,我想删除内容转移编码:从身体中二进制。但是我不知道如何。我尝试使用以下代码,但此请求仍然存在。这是我正在使用的代码:

request = given()
            .header("Authorization", "Bearer " + LoginSteps.accessToken)
            .queryParam("memberId", memberId)
            .multiPart("receipt", new File(receiptFilePath), "image/jpeg")
            .urlEncodingEnabled(false)
            .config(RestAssuredConfig.config()
                    .encoderConfig(EncoderConfig
                            .encoderConfig()
                            .appendDefaultContentCharsetToContentTypeIfUndefined(false)
                            .encodeContentTypeAs("image/jpeg", io.restassured.http.ContentType.ANY)));

request.post(baseUrl + endpoint);

有人可以告诉我如何从此请求中摆脱内容转移编码吗?

I'm currently testing a very specific API, that refuses to accept a request which has Content-Transfer-Encoding: binary. I throws a 415 - unsupported media type error. However, when I send the same file and build the same request using postman, it accepts it without issues. Looking at the logs of what is received in the service, the only difference in the two requests is that the restassured one has Content-Transfer-Encoding: binary in the body. Here's how it looks:

enter image description here

So for the sake of debugging and pinpointing if this is indeed the cause of the request failing, I would like to remove Content-Transfer-Encoding: binary from the body. yet I have no idea how. I tried using the following code, yet the request still arrives with it present. Here is the code I'm using:

request = given()
            .header("Authorization", "Bearer " + LoginSteps.accessToken)
            .queryParam("memberId", memberId)
            .multiPart("receipt", new File(receiptFilePath), "image/jpeg")
            .urlEncodingEnabled(false)
            .config(RestAssuredConfig.config()
                    .encoderConfig(EncoderConfig
                            .encoderConfig()
                            .appendDefaultContentCharsetToContentTypeIfUndefined(false)
                            .encodeContentTypeAs("image/jpeg", io.restassured.http.ContentType.ANY)));

request.post(baseUrl + endpoint);

Can anyone tell me how to get rid of Content-Transfer-Encoding from this request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文