【问题标题】:MultiPart PUT request not working in spring bootMultiPart PUT 请求在 Spring Boot 中不起作用
【发布时间】:2019-10-23 04:21:49
【问题描述】:

我有以下 curl 请求

curl -X PUT http://localhost:50005/did:corda:tcn:77ccbf5e-4ddd-4092-b813-ac06084a3eb0  -H 'content-type:multipart/form-data'  -F 'instruction=hgfhhf'

我正在尝试阅读我的 Spring Boot 控制器中的指令,如下所示

@PutMapping(value = "{id}",
    produces = arrayOf(MediaType.APPLICATION_JSON_VALUE),
    consumes = arrayOf(MediaType.MULTIPART_FORM_DATA_VALUE))

fun createID(@PathVariable(value = "id") id: String,
    @RequestParam("instruction") instruction: String ) : ResponseEntity<Any?> 

但是上面的代码返回

"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'instruction' is not present"

【问题讨论】:

    标签: rest spring-boot curl kotlin


    【解决方案1】:
    1. 删除未使用的:
      consumes = arrayOf(MediaType.MULTIPART_FORM_DATA_VALUE)
      
    2. 您错过了请求参数说明(在请求中),试试这个:

      curl -X PUT -G 'http://localhost:50005/did:corda:tcn:77ccbf5e-4ddd-4092-b813-ac06084a3eb0' -d 'instruction=hgfhhf'
      

      也可以看看CURL Command Line URL Parameters

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2017-08-10
      • 1970-01-01
      • 2019-05-01
      • 2014-05-15
      • 2018-05-20
      • 2015-09-30
      • 1970-01-01
      • 2021-01-10
      相关资源
      最近更新 更多