带有图像和数据的HTTP帖子 [英] HTTP post with image and data

查看:103
本文介绍了带有图像和数据的HTTP帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache HTTP Client来进行呼叫休息端点。

I am using apache HTTP Client for callin rest endpoints.

我想用图像和一些更多的表单数据作为参数来调用POST请求。我可以单独执行这些请求,例如首先用于表单数据,另一个用于单独的图像。

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.

以下是api电话

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


推荐答案

使用多部分请求 Commons Apache File Upload API 具有非常好的API。
Apache Commons HttpClient也有客户端的API。

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

否则,使用支持多部分数据的Servlet 3.0容器。其中字符串部分类型将随 HttpServletRequest.getParameter()方法。可以使用文件类型部分nofollow> HttpServletRequest.getPart()方法。

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.

这篇关于带有图像和数据的HTTP帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆