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