今天在工作有一个需求需要使用后台模拟html表单上传文件,想到使用apache-httpcomponents来处理。主要使用的包有
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.5</version>
</dependency>
模拟content-type为multipart-form主要使用的类是MultipartEntity,该类能够很好的支持多文件的上传。简单实现代码如下:
private static MultipartEntity getMultipartEntity() {
String file1 = FileUploadHttpclient.class.getResource("sampleUploadFile1.txt").getFile();
String file2 = FileUploadHttpclient.class.getResource("sampleUploadFile2.txt").getFile();
MultipartEntity multipartEntity = new MultipartEntity();
//后台接收什么就添加什么
multipartEntity.addPart("text1", StringBody.create("this is httpclient"));
multipartEntity.addPart("file1", new FileBody(new File(file1)));
multipartEntity.addPart("file2", new FileBody(new File(file2)));
return multipartEntity;
}
然后再配上HttpPost 和 DefaulHttpClient 即可完成模拟表单的上传。
工程中不仅包含httpclient的上传,还包含页面表单的上传和后台用commons-fileupload实现的服务。
分享到:
相关推荐
apache-httpcomponents-httpmime.jar
网络爬虫需要的org.apache.http包)(httpcomponents-client-4.2.5-bin.tar)
commons-codec-1.11.jar commons-logging-1.2.jar fluent-hc-4.5.10.jar httpclient-4.5.10.jar httpclient-cache-4.5.10.jar httpclient-osgi-4.5.10.jar httpclient-win-4.5.10.jar ...jna-4.5.2.jar ...
Apache HttpComponents客户端欢迎使用Apache HttpComponents项目的HttpClient组件。建筑说明有关从源代码进行构建的信息,请参阅 。依存关系HttpClient主模块需要与Java 7兼容的运行时,并且依赖于以下外部库:其他...
org.apache.httpcomponents.client4.11org.apache.httpcomponents.client4.11org.apache.httpcomponents.client4.11
... ... 赠送Maven依赖信息文件:...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
apache-httpcomponents-httpcore.jar.zip官网下的解压可用
赠送jar包:httpclient-4.5.13.jar;...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
org.apache.httpcomponents.httpclient_4.5.4.jar 官方说明: The Apache HttpComponents™ project is responsible for creating and maintaining a toolset of low level Java components focused on ...
... ... 赠送Maven依赖信息文件:httpmime-4.5.13.pom...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
apache-httpcomponents-httpclient-cache
... ... 赠送Maven依赖信息文件:httpcore-4.4.14.pom...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
HttpComponents用法解析 Java模拟浏览器发送请求
Apache HttpComponents 已经取代了 HttpClient 。 官方内容:The Commons HttpClient project is now end of life, and is no longer being developed. It has been replaced by the Apache HttpComponents project ...
官网下载地址:http://hc.apache.org/downloads.cgi 官网下载的未改动过,都是英文的 包含的内容: 1.examples 例子 2.javadoc api 3.lib 全部包 4.tutorial 官网教程 5.源码 最近学习httpclient,在网上搜的...
Apache HttpComponents 核心欢迎使用 Apache HttpComponents 项目的 HttpCore 组件。搭建说明有关从源代码构建的说明,请参阅 。依赖关系HttpCore 需要与 Java 1.8 兼容的运行时。许可Apache HttpComponents Core ...
... ... 赠送Maven依赖信息文件:httpcore-4.4.10.pom...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
适合java post http开发 jar文件
jar包,官方版本,自测可用