客户端发送的请求在语法上不正确().+ Spring,RESTClient [英] The request sent by the client was syntactically incorrect ().+Spring , RESTClient

查看:251
本文介绍了客户端发送的请求在语法上不正确().+ Spring,RESTClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSON对象使用Spring MVC.尝试从RESTClient发送JSON对象时,我得到

I am working with Spring MVC using JSON objects. while I am tring to send JSON Object from RESTClient, I am getting

HTTP状态400-客户端发送的请求在语法上不正确().

HTTP Status 400 - The request sent by the client was syntactically incorrect ().

这是我的控制器

ObjectMapper mapper=new ObjectMapper();
@RequestMapping(value = "/addTask", method = RequestMethod.GET)
       public ModelAndView addTask(@RequestParam("json") String json) throws JsonParseException, JsonMappingException, IOException 
       {
          System.out.println("Json object from REST : "+json);
          Task task=(Task) mapper.readValue(json, Task);
          service.addService(task);
          return new ModelAndView("Result");
       }

我的请求网址:http://localhost:8080/Prime/addTask

我的Json对象:

{"taskName":没什么","taskId":1234,"taskDesc":没做什么"}

{"taskName":"nothing","taskId":1234,"taskDesc":"nothing doing"}

我也尝试在RESTClient中指定"Content-Type:application/json",但仍然出现相同的错误

Also i tried specifying "Content-Type: application/json" in RESTClient but still am getting the same error

推荐答案

尝试一下

更改

@RequestParam("json") String json

收件人

 @RequestBody Task task

如果您对POST方法不感兴趣,可以尝试一下

If you are not interested in POST method you can try this

@RequestMapping(value = "/addTask", method = RequestMethod.GET)
   public ModelAndView addTask(@RequestParam("json") String json)

@RequestMapping(value = "/addTask/{taskName}/{taskId}/{taskDesc}", method = RequestMethod.GET)
   public ModelAndView addTask(@RequestParam("taskName") String taskName,
@RequestParam("taskId") String taskId,@RequestParam("taskDesc") String taskDesc)

并将您的URL更改为

http://localhost:8080/Prime/addTask/mytask/233/testDesc

这篇关于客户端发送的请求在语法上不正确().+ Spring,RESTClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆