首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

运用InputStreamEntity 边读取边上传文件

2012-06-29 
使用InputStreamEntity 边读取边上传文件HttpClient httpclient new DefaultHttpClient() HttpPost htt

使用InputStreamEntity 边读取边上传文件

HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://localhost/upload"); File file = new File("/path/to/myfile"); FileInputStream fileInputStream = new FileInputStream(file); InputStreamEntity reqEntity = new InputStreamEntity(fileInputStream, file.length()); httppost.setEntity(reqEntity); reqEntity.setContentType("binary/octet-stream"); HttpResponse response = httpclient.execute(httppost); HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) {   responseEntity.consumeContent(); } httpclient.getConnectionManager().shutdown();
1 楼 ljy520zhiyong 2012-06-14   可不可以发那个http://localhost/upload的action看看?

热点排行