我正在使用Spring Restful Web服务&请求正文包含请求标题,如下所示:
@RequestMapping(value = "/mykey",method = RequestMethod.POST,consumes="applicaton/json")
public ResponseEntity@H_502_8@
我想传递一个名为“X-MyHeader”的可选请求标头.如何在Spring休息服务中指定此可选请求标头?
另外,如何在响应头中传递相同的值?
谢谢!
更新:我刚刚发现我可以在请求标头中设置required = false,因此解决了一个问题.现在,剩下的唯一问题是如何在响应中设置标头?
最佳答案
这个问题@R_502_6329@得到解答:
In Spring MVC,how can I set the mime type header when using @ResponseBody
In Spring MVC,how can I set the mime type header when using @ResponseBody
以下是代码示例:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-httpentity
@RequestMapping("/something")
public ResponseEntityhttpentityirst("MyRequestHeader");
byte[] requestBody = requestEntity.getBody();
// do something with request header and body
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("MyResponseHeader","MyValue");
return new ResponseEntity@H_502_8@
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。