问题描述
我似乎无法为我工作,我在其他帖子中也看到了此事,希望有人可以发现我在做错什么.我正在尝试获取对此其余api的请求正文,但似乎无法撤回我需要的东西,只是在下面的字符串中获取null.
I cannot seem to get this to work for me ,I have seen this in other posts and was hoping someone may be able to spot what im doing wrong.I am trying to get the body of a request to this rest api but cannot seem to pull back what i need and just get null in the string below.
@POST
@Path("/SetFeeds")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String setFeed(@PathParam("name")String name2, @QueryParam("name") String name,@Context UriInfo uriInfo){
MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
String query = uriInfo.getRequestUri().getQuery();
String response = queryParams.getFirst("name");
return response;
}
推荐答案
用于接受请求正文的方法参数不应带有任何注释(在个别情况下,如个别形式的参数和多部分除外).因此,要获取原始JSON,您可以简单地添加一个String参数
A method parameter to accept the body of the request should not be annotated with anything (except in few cases like individual form params and multipart). So to get the raw JSON, you could simply add a String parameter
public String setFeed(@PathParam("name")String name2,
@QueryParam("name") String name,
@Context UriInfo uriInfo,
String jsonBody){
或者,如果您想做更普通的事情并使用POJO(因此您不需要自己解析JSON),则应查看
Or if you want to do the more common thing and use POJOs (so you don't need to parse the JSON yourself), you should look at this answer
这篇关于Rest Api发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!