【发布时间】:2011-12-16 01:42:06
【问题描述】:
我正在将图像从 android 手机发送到服务器,这是一个 servlet,我为此使用 HttpClient 和 HttpPost,并在发送前使用 ByteArrayBody 存储图像。
如何从 Servlet 中的 post 请求中提取图像。
这是我发送帖子请求的代码
String postURL = //server url;
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(postURL);
ByteArrayBody bab = new ByteArrayBody(imageBytes,"file_name_ignored");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("source", bab);
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
【问题讨论】: