服务器间通过HTTP协议传送文件

本文介绍了如何通过HttpClient在服务器之间传输文件。主要方法包括使用InputStream对象和直接上传文件,涉及HttpPost请求、MultipartEntityBuilder、文件读取以及响应处理。
摘要由CSDN通过智能技术生成

服务器间传送文件

参考文章http://www.baeldung.com/httpclient-multipart-upload

首先,引入发送Http请求的依赖

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.6</version>
</dependency>

1、使用HttpClient发送InputStream对象

public void inputStreamUpload() {
        //创建HttpClient对象
        CloseableHttpClient client = HttpClients.createDefault();
        //构建POST请求   请求地址请更换为自己的。
        //1)
        HttpPost post = new HttpPost("http://localhost:8003/upl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值