HTTP post with image and data

末鹿安然 提交于 2019-12-13 05:58:23

问题


I am using apache HTTP Client for callin rest endpoints.

I want to call a POST request with image and some more form data as parameters. I can do them separately with to requests like first for the form data and the other for the image alone.

Is there any possible solution so that i can do it with one request.

Below is the api call

http://<url>?hint=hi&def=ready&image=<imagefile>

回答1:


Use Multipart Request. Commons Apache File Upload API has very good API for the same. Apache Commons HttpClient has the API for client also.

Else, use Servlet 3.0 container which has support for multipart data. Where the String part type will be provided with HttpServletRequest.getParameter() method. And the File type parts can be retrieved using HttpServletRequest.getPart() method.



来源:https://stackoverflow.com/questions/10810490/http-post-with-image-and-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!