问题描述
我已经用 java 编写了一个 REST web 服务.但是如果我想接收 Accept : application/json
标头,该怎么做?如果我想接收更多自定义标头,例如CDMI-Speciation-1.0" ,我怎样才能收到两个标头?
i have write a REST web service in java.But If I want to receive Accept : application/json
header ,how to do that?If I want to receive more custom header like "CDMI-Speciation-1.0" , how can i receive both headers?
我的网络服务是这样的:
My web service is like that:
@PUT
@Consumes("application/json")
@Produces("application/json")
public vodi doPut(){.....}
我的请求应该是这样的:curl --header "Content-Type:application/json" --header
Accept:application/json" --header "CDMI-Specification-1.0" http://localhost/user -v
My request should be like : curl --header "Content-Type:application/json" --header
Accept:application/json" --header "CDMI-Specification-1.0" http://localhost/user -v
我所知道的是 @Conusmes
用于内容类型".是吗?
What I know is @Conusmes
is for "Content-Type" .Is it?
谢谢
推荐答案
有可以检索http头的注解,例如:
There are annotations that can retrieve the http headers, for example:
@PUT
@Consumes("application/json")
@Produces("application/json")
public void doPut(@Context HttpHeaders hh){
.....
}
您还可以检索单个标题:
You can also retrieve a single header:
@PUT
@Consumes("application/json")
@Produces("application/json")
public void doPut(@HeaderParam("Accept") acceptHeader){
.....
}
请参阅此处了解更多信息.
这篇关于如何收到“接受"REST Web 服务服务器端的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!