我似乎无法让它为我工作,我在其他帖子中看到过这个,希望有人能够发现我做错了什么。我正在尝试获取对这个 rest api 的请求正文,但是似乎无法拉回我需要的东西,只能在下面的字符串中得到 null。
@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,您可以简单地添加一个字符串参数
public String setFeed(@PathParam("name")String name2,
@QueryParam("name") String name,
@Context UriInfo uriInfo,
String jsonBody){
或者如果你想做更常见的事情并使用 POJO(这样你就不需要自己解析 JSON),你应该看看 this answer
关于java - Rest Api Post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31967164/