There is such a method:

@RequestMapping(value = "/request", method = RequestMethod.POST) public @ResponseBody ServiceResponse regDocs( @RequestPart("uploadInfo") UploadInfo uploadInfo, MultipartHttpServletRequest request) { ... } 

The UploadInfo class in turn also consists of classes. I'm trying to call this POST method via Advanced REST-client (this is a plugin for Chrome), I specify the address: http: // host: 9080 / services / request I don’t know where to specify the values ​​of this class? I tried to write json something like

 { "uploadInfo":[{ "Class1":"value", "Class2":"value", ... }] } 

tried a few more options, all the time writing

Error 400: Required request part 'uploadInfo' is not present.

uploadInfo do I need to fill in uploadInfo ?

  • Well, it usually looks like a page is being formed (for example, Jsp) in which you form your POST request and set the fields of this page in accordance with the fields of your UploadInfo object. In principle, in any HowTo it is. What is the problem? - barmaglott 3:49 pm
  • Yes, we have a self-written application that tests this functionality. But our boss does not like it, he needs to be tested through this plugin for chrome. - Stone Jack
  • There, obviously, not application / json is accepted as input, but multipart / form-data or x-www-form-urlencoded, they are seralized in a different way - etki

1 answer 1

Statute 400 says that this is a bad request, and a bad one because of incorrect headers. in @RequestMapping you need to add the necessary leader, for example: @RequestMapping(value = "/request", method = RequestMethod.POST, consumes="application/json") and add the necessary Content-Type: application/json to the request on the client

about @RequestMapping

The consumes parameter specifies the content type of the request body. for example, consumes = "application / json" specifies that the Content-Type of the request that the client sent should be "application / json". You can set a negative indication: consumes = "! Application / json". Then any Content-Type other than the specified will be required. multiple values ​​are allowed: ("text / plain", "application / *).

The produces parameter defines the format of the value returned by the method. If the Accept header is not specified on the client header, it does not matter what is set in produce. If the Accept header is set, then the value of produces must match it in order for the result to be successfully returned to the client. The produce parameter may also contain an enumeration of values.

  • Thanks, I will try - Stone Jack