spring - Empty request body gives 400 error -


my spring controller method looks this:

@requestmapping(method=requestmethod.put, value="/items/{itemname}") public responseentity<?> updateitem(@pathvariable string itemname, @requestbody byte[] data) {     // code saves item } 

this works fine except when try put zero-length item, http error: 400 bad request. in case method never invoked. expecting method should invoked "data" parameter set zero-length array.

can make request mapping work when content-length 0?

i using spring framework version 4.1.5.release.

setting new byte[0] not send content on request body. if set spring mvc logs trace should see message saying required request body content missing root cause of 400 bad request

to support case should make @requestbody optional

@requestmapping(method=requestmethod.put, value="/items/{itemname}") public responseentity<?> updateitem(@pathvariable string itemname, @requestbody(required = false) byte[] data) {   // code saves item } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -