【问题标题】:can not send a post request using postman无法使用邮递员发送发布请求
【发布时间】:2018-06-05 18:27:00
【问题描述】:


我正在尝试使用邮递员打磨发布请求。 出于某种原因,我收到 400 Bad Request - 缺少所需的请求正文。 我的控制器在 spring boot 环境中。
我的控制器:

    @RestController
    public class HagarController {

      @PostMapping(value = "/hagar")
      @ResponseStatus(HttpStatus.OK)
      public void hagar(@RequestBody String name, @RequestBody String id) 
      throws Exception{
          System.out.println("my name is: " + name +" id: " + id);
      }
    }

The postman request img

谢谢!!

【问题讨论】:

    标签: http post httpclient postman spring-restcontroller


    【解决方案1】:

    这就是我的做法,希望对你有帮助:

    @RestController
    public class HagarController {
    
      @ResponseMapping(value = "/add", method = RequestMethod.POST)
      public void hagar(@RequestBody String name, @RequestBody String id) 
          System.out.println("my name is: " + name +" id: " + id);
    }
    

    在邮递员中,您可能在标题中添加了: 看图片enter image description here

    【讨论】:

    • 解释一下怎么样?看来您添加的唯一内容是method = RequestMethod.POST
    • 我不确定。我也是邮递员的新手,但这种方法对我有用,我认为它也会帮助 Hagar。
    猜你喜欢
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 2018-07-12
    相关资源
    最近更新 更多