how to received “Accept” header in REST web service server side

不羁的心 提交于 2020-01-07 02:05:33

问题


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(){.....}

My request should be like : curl --header "Content-Type:application/json" --header Accept:application/json" --header "CDMI-Specification-1.0" http://localhost/user -v

What I know is @Conusmes is for "Content-Type" .Is it?

thanks


回答1:


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){
    .....
}

See here for more information.



来源:https://stackoverflow.com/questions/6503960/how-to-received-accept-header-in-rest-web-service-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!