java - 如何通过 post man post 请求在 header 中传递对象?

标签 java post http-headers postman

我正在使用 postman 并尝试在 header 中传递一个对象,但在从字符串转换为对象时出现错误...我该怎么做?

我附上 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)

    }

我做错了什么?

谢谢

最佳答案

解决方案:

我想我找到了解决方案,它将对象从标题移动到正文并将代码更改为如下所示:

@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)

}

关于java - 如何通过 post man post 请求在 header 中传递对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53885981/

相关文章:

java - ArrayList无法解析变量类型

php - Jquery Post - Php 遇到问题

node.js - 如何向redis服务器发出post请求

amazon-s3 - AMAZON AWS S3 递归地更改/添加整个存储桶的元数据

http - 查看响应头的工具

java - 不支持中文的 Content-Disposition 文件名

java - 在 JavaFx 中将形状或对象从一个 fxml 复制/克隆到另一个 fxml

java - 如何通过点击li元素触发Spring boot表单提交?

java - 使用泛型时创建二叉搜索树类的实例?

Ruby:如何通过 HTTP 将文件作为多部分/表单数据发布?