可能是重复问题:
在安卓中发送post数据
如何通过http post方式发送图像及表单数据,比如图像名称等,到指定的url,即一个aspx页面。
可能是重复问题:
在安卓中发送post数据
如何通过http post方式发送图像及表单数据,比如图像名称等,到指定的url,即一个aspx页面。
检查此代码以发送带有标题、说明、名称等的图像。
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);
}
bitmap是图像位图。