MultiPart PUT请求在春季启动中不起作用

时间:2019-06-07 16:22:07

标签: rest spring-boot curl kotlin

我有以下卷曲请求

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"

1 个答案:

答案 0 :(得分: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

相关问题