首页 > 解决方案 > REST API - HTTP 状态 415 - 无法使用内容类型

问题描述

我有一个javax.ws.rs.*REST 端点,我正在尝试使用它上传文件。因此端点接收到一个文档和一个参数列表。

它得到以下错误:

HTTP 状态 415 - 无法使用内容类型

问题

任何想法我做错了什么以及如何更改我的代码以使用文档和参数?

这是我的代码:

@POST
@Path("override")
@ApiOperation(value="Receives the override info for a trip ('overrideConclusion':'Approved'/'Reject').")
@ApiResponses({
        @ApiResponse(code=200, message="Success"),
        @ApiResponse(code=404, message="Not Found")
})
@Consumes(MediaType.MULTIPART_FORM_DATA)
//@Consumes({"text/*","application/*"})
@Produces(MediaType.APPLICATION_JSON)
public Response override(@HeaderParam("Authorization") String token, @Context HttpServletRequest request,
                         @ApiParam(required = true) byte[] data, @ApiParam(required = true) @QueryParam("tripId") Long tripId, @QueryParam("overrideReason") String overrideReason,
                         @QueryParam("overrideConclusion") String overrideConclusion, @QueryParam("authorizedApproverPersonId") Long authorizedApproverPersonId, @QueryParam("fileName") String fileName) {

我使用 Postman 来测试它:

要上传的文件

在此处输入图像描述

参数

在此处输入图像描述

完整错误:

<body>
    <h1>HTTP Status 415 - Cannot consume content type</h1>
    <HR size="1" noshade="noshade">
    <p><b>type</b> Status report</p>
    <p><b>message</b> <u>Cannot consume content type</u></p>
    <p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by
            the requested resource for the requested method (Cannot consume content type).</u></p>
    <HR size="1" noshade="noshade">
    <h3>JBoss Web/7.0.1.Final</h3>
</body>

标签: javarestjax-rs

解决方案


推荐阅读