由网友(人潮那么挤,心却那么空)分享简介:可能重复: 发送POST数据的android 如何通过HTTP POST随着表单数据即映像名称发送图像等How to send a image via http post along with the form data i.e image name etc到指定的URL ..这是URL中的 ASPX t...
可能重复: 发送POST数据的android
如何通过HTTP POST随着表单数据即映像名称发送图像等
How to send a image via http post along with the form data i.e image name etc
到指定的URL ..这是URL中的 ASPX
to a specified url .. which is the url of a aspx.
推荐答案
勾选此code与标题发送图片,标题,名称等,
Check this code for Sending Image with Title,Caption,Name etc,
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("You Link");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("name", new StringBody("Name"));
reqEntity.addPart("Id", new StringBody("ID"));
reqEntity.addPart("title",new StringBody("TITLE"));
reqEntity.addPart("caption", new StringBody("Caption"));
try{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
reqEntity.addPart("picture", bab);
}
catch(Exception e){
//Log.v("Exception in Image", ""+e);
reqEntity.addPart("picture", new StringBody(""));
}
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
其中位图图像位图。
Where bitmap is the Image Bitmap.
让我知道如果你发现任何问题。
Let me know if you find any difficulty.
由于Venky。
相关推荐
最新文章