java - 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>
解决方案
推荐阅读
- postgresql - 用docker安装的postgresql的密码会自动更改吗?
- ms-access - 在访问查询中将 .0 添加到不带小数的数字
- python - 解析系统 GTA V
- c - 反对 free_if_heap(void *ptr)?
- postgresql - PostgreSQL:错误:列“bb”不存在
- python - 在 groupby 方法中实例化一个类
- javascript - Ag-grid Pivot“删除重复项”功能,如 Excel
- java - 如何从 Java 同时启动服务器和传递命令?
- java - Libgdx 在使用 Java(TM) Platform SE Binary 打开时立即崩溃
- r - 我无法访问用于网络抓取的子节点