WebResource分段发布请求

编程入门 行业动态 更新时间:2024-10-25 07:33:57
本文介绍了WebResource分段发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用java测试将发布请求发送到此rest函数:

I need to send post request using java test to this rest function :

@RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody String handleFileUpload(@PathVariable Long ownerId, @RequestBody MultipartFile file, HttpServletResponse response) throws IOException { //Some function }

这是我的审判

this is my trial:

File file = new File("filePath"); FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE); WebResource webResource = createResourceClient("restPath", user); ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, fileDataBodyPart);

,错误提示:

and the error says:

当前请求不是多部分请求"

"The current request is not a multipart request"

推荐答案

下面的代码将文件和ContentDispostion都发送到REST API.

The below piece of code will send both the file and the ContentDispostion to the REST API.

FormDataBodyPart formPart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("YourFileName").build(), inputStream,MediaType.APPLICATION_OCTET_STREAM_TYPE); MultiPart multipart = new FormDataMultiPart().bodyPart(formPart); resource = resource.path("Your Rest api path"); ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, multipart);

更多推荐

WebResource分段发布请求

本文发布于:2023-10-10 22:33:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebResource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!