读书人

运用InputStreamEntity 边读取边上传文

发布时间: 2012-06-29 15:48:46 作者: rapoo

使用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看看?

读书人网 >移动开发

热点推荐