400(错误请求),在Spring中发送json

400(错误请求),在Spring中发送json,spring,servlets,http-status-code-400,Spring,Servlets,Http Status Code 400,我试图将json字符串发送到Spring控制器,得到400个错误的请求作为响应 我正在使用Spring4.0.3 这是我的控制器 @Controller public class Customer{ @RequestMapping(value = "/apis/test", method = RequestMethod.GET, produces = "application/json") public @ResponseBody String test(HttpServlet

我试图将json字符串发送到Spring控制器,得到400个错误的请求作为响应

我正在使用Spring4.0.3

这是我的控制器

@Controller
public class Customer{

    @RequestMapping(value = "/apis/test", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody String test(HttpServletRequest params) throws JsonIOException {
        String json = params.getParameter("json");
        JsonParser jObj = new JsonParser();
        JsonArray  jsonObj = (JsonArray ) jObj.parse(json);

        for(int i = 0; i < jsonObj.size(); i++) {
            JsonObject jsonObject = jsonObj.get(i).getAsJsonObject();
            System.out.println(jsonObject.get("name").getAsString());

        }
        return json;
    }
}
请帮我解决这个问题

@RequestMapping(value = "/apis/test", method = RequestMethod.GET, produces = "application/json")
上面的意思是这是一个HTTP GET方法,通常不接受数据。您应该使用HTTP POST方法,例如:

@RequestMapping(value = "/apis/test", method = RequestMethod.POST, consumes = "application/json")
    public @ResponseBody String test(@RequestParam final String param1, @RequestParam final String param2, @RequestBody final String body) throws JsonIOException {
然后可以执行POST/api/test?param1=one¶m2=two,并在请求的RequestBody中添加字符串


我希望这有帮助

我正在使用angular JS进行集成共享浏览器中的请求。在网络选项卡中捕获请求我们需要知道如何调用此请求。。。请分享详细信息[链接]和[链接]。。它在localhost中工作。我在live server中遇到错误任何服务器端异常?实际上我想用json传递一些其他参数,比如我更新了答案以显示如何添加其他参数扫描您告诉我如何从POST方法检索数据??我正在尝试使用HttpServletRequest参数,但它给出了null值。上面的代码向您展示了如何获取参数、使用RequestParam和RequestBody注释的方法参数。您可以使用HttpServletRequest,但级别要低一点。您能告诉我如何更好地使用get和POST方法获取10个以上的参数吗??事实上,我没有得到正确的方法。。我试过很多例子,但在post方法中,它会产生问题