问题
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