如何通过邮递员发布请求在标头中传递对象?

时间:2018-12-21 13:55:08

标签: java post http-headers postman

我正在使用邮递员,并尝试在标头中传递一个对象,但是在从字符串转换为对象时出现错误...我该怎么办?

我要附上邮递员的照片

https://imgur.com/a/5wAxIYf

这是服务器上的代码:

@RequestMapping(
      path= arrayOf(
              "/wristbands/upload",
              "/wristbands/upload/"),
      method = arrayOf(RequestMethod.POST),
      consumes = arrayOf(MediaType.APPLICATION_JSON_UTF8_VALUE))
  open fun wristbandProcessNewAlgorithem(@RequestHeader(name = "X-V", required = true)  wristbandRecords: WristbandRecordNewInputDTO): ResponseEntity<*>{

   var res=wristbandProcessingService.processWristbandNewAlgorithem(wristbandRecords)
  return ResponseEntity(res,HttpStatus.OK)

    }

我在做什么错了?

谢谢

1 个答案:

答案 0 :(得分:1)

解决方案:

我想我找到了解决方案,它是将对象从标头移动到主体,并更改代码,如下所示:

@RequestMapping(
      path= arrayOf(
              "/wristbands/upload",
              "/wristbands/upload/"),
      method = arrayOf(RequestMethod.POST),
      headers = arrayOf("X-V"),
      consumes = arrayOf(MediaType.APPLICATION_JSON_UTF8_VALUE))
 open fun wristbandProcessNewAlgorithem(@RequestBody  wristbandRecords: WristbandRecordNewInputDTO): ResponseEntity<*>{

var res=wristbandProcessingService.processWristbandNewAlgorithem(wristbandRecords)
return ResponseEntity(res,HttpStatus.OK)

}