使用 text/xml 获取 http 415,不支持的媒体类型

罗恩史蒂文森

我有一个 jersey 端点(JAX-RS),我试图用文本/xml 请求命中它。我正在返回一个 http 415,但我不明白为什么。这是信息。有任何想法吗?谢谢。

@Path("/bid")
@Produces("text/xml;charset=ISO-8859-1")
@Consumes({"text/xml", "application/xml"})
@Resource
public class BidController {

@RolesAllowed("blah")
@POST
public Response bid(final HttpServletRequest request) {

我通过 Postman(REST 客户端)点击它并发送 {"Content-Type":"text/xml"}

我的 POST 正文绝对是格式良好的 xml。

史蒂夫·C

您收到 415 响应,因为 JAX-RS 不知道如何将传入的 XML 转换为HttpServletRequest.

如果你真的想访问请求,那么你需要用@javax.ws.rs.core.Context注释它

@RolesAllowed("blah")
@POST
public Response bid(@Context final HttpServletRequest request) {

但是,正如您所说,您正在使用text/xml,那么您实际上可能想要:

@POST
public Response bid(final MyRequest request) {
    ...
}

在哪里MyRequest声明如下:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class MyRequest {

     @XmlElement
     int field1;

     @XmlElement
     String field2;

     ...
}

它对应于 XML,如:

<MyRequest>
    <field1>11327</field1>
    <field2>some string
</MyRequest>

JAX-RS 规范要求实现能够通过 JAXB 解码传入的 text/xml 和编码传出的 text/xml。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

获取HTTP状态415-泽西岛不支持的媒体类型

在Spotify API的授权过程中获取HTTP 415不支持的媒体类型

尝试使用Rest API创建Hpalm缺陷时,获取“ 415不支持的媒体类型”

415不支持的媒体类型HTTP

HTTP 415不支持的媒体类型

HTTP 415 JSON不支持的媒体类型错误

不支持的媒体类型,Http 错误 415

Grizzly HTTP Server 415不支持的媒体类型

JAX-RS:HTTP状态415-不支持的媒体类型

Keycloak admin-cli throwing-HTTP错误-415不支持的媒体类型

适配器部署失败:HTTP 415-不支持的媒体类型

服务器返回 HTTP 响应代码:415 不支持的媒体类型

Mule APIkit:“找不到流”,而不是HTTP 415不支持的媒体类型

ASP.NET Core表单POST导致HTTP 415不支持的媒体类型响应

带有JSON POST的Http 415不支持的媒体类型错误

调用Web API 2端点时HTTP 415不支持的媒体类型错误

Dynamics NAV Odata 请求返回 HTTP/1.1 415 不支持的媒体类型

使用wp_remote_post时出现415错误“不支持的媒体类型”

使用邮递员测试.Net Web API时得到415不支持的媒体类型

球衣RESTful api在使用FormDataMultipart时答复415不支持的媒体类型

Web应用程序异常:javax.ws.rs.NotSupportedException:HTTP 415不支持的媒体类型

远程服务器返回错误:(415)在asp.net中使用API的不支持的媒体类型

使用Spring RestTemplate客户端的Spring Boot Actuator关闭端点:错误415不支持的媒体类型

415不支持的媒体键入http.post角度请求

未使用自定义HTTP消息转换器,未支持的媒体类型为415

将带有JSON数据的GET请求从Axios发送到Asp.net核心ActionResult,而不会获取(415不支持的媒体类型)

HTTPS不支持但不支持HTTP的获取505 HTTP版本

Jersey 415不支持的媒体类型

415不支持的媒体类型”错误