How can I make a multipart/form-data POST request using Java?

后端 未结 11 1474
攒了一身酷
攒了一身酷 2020-11-22 05:56

In the days of version 3.x of Apache Commons HttpClient, making a multipart/form-data POST request was possible (an example from 2004). Unfortunately this is no longer possi

11条回答
  •  情深已故
    2020-11-22 06:32

    My code for sending files to server using post in multipart. Make use of multivalue map while making request for sending form data

      LinkedMultiValueMap map = new LinkedMultiValueMap<>();
            map.add("FILE", new FileSystemResource(file));
            map.add("APPLICATION_ID", Number);
    
       httpService.post( map,headers);
    
    

    At receiver end use

    @RequestMapping(value = "fileUpload", method = RequestMethod.POST)
        public ApiResponse AreaCsv(@RequestParam("FILE") MultipartFile file,@RequestHeader("clientId") ){
    //code
    }
    

提交回复
热议问题