在使用HttpClient时,怎么上传文件到服务器?
很简单,只需要构建一个FileEntity
File file=new File("file.txt");FileEntity entity=new FileEntity(file); HttpPost httppost=new HttpPost("http://www.baidu.com/");httppost.setEntity(entity);
然后提交这个Post即可:
httpClient.execute(httppost);