mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
HttpRequest增加setFixedLengthStreamingMode方法
This commit is contained in:
@@ -351,6 +351,20 @@ public class HttpConnection {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置固定长度流模式,默认为0,表示不设置固定长度流模式,即默认为按需发送数据长度。<br>
|
||||
* 当发送大文件时,如果每次发送的数据长度不一致,可能造成接收方无法正常接收,此时可以设置固定长度流模式,此时发送的数据长度为contentLength,不足部分用0补齐。
|
||||
*
|
||||
* @param contentLength 固定长度
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setFixedLengthStreamingMode(long contentLength){
|
||||
if(contentLength > 0){
|
||||
conn.setFixedLengthStreamingMode(contentLength);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采用流方式上传数据,无需本地缓存数据。<br>
|
||||
* HttpUrlConnection默认是将所有数据读到本地缓存,然后再发送给服务器,这样上传大文件时就会导致内存溢出。
|
||||
|
@@ -350,6 +350,19 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
return this.httpConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置固定长度流模式,默认为0,表示不设置固定长度流模式,即默认为按需发送数据长度。<br>
|
||||
* 当发送大文件时,如果每次发送的数据长度不一致,可能造成接收方无法正常接收,此时可以设置固定长度流模式,此时发送的数据长度为contentLength,不足部分用0补齐。
|
||||
*
|
||||
* @param contentLength 固定长度
|
||||
* @return this
|
||||
* @since 5.8.33
|
||||
*/
|
||||
public HttpRequest setFixedLengthStreamingMode(long contentLength){
|
||||
this.httpConnection.setFixedLengthStreamingMode(contentLength);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求方法
|
||||
*
|
||||
|
Reference in New Issue
Block a user