目录

RequestBody

Class Info

public abstract class RequestBody

网络请求体。

Public Constructor Summary

Constructor Name

public RequestBody()

默认的构造方法。

Public Method Summary

Qualifier and Type

Method Name and Description

public long

contentLength()

返回数据长度。

public abstract String

contentType()

获取网络数据的编码类型。

public boolean

isDuplex()

是否开启全双工请求。

public abstract void

writeTo(OutputStream outputStream)

将请求体数据写到输出流。

Public Constructors

[h2]RequestBody

Constructor

public RequestBody()

默认的构造方法,构造RequestBody对象。

Public Methods

[h2]contentLength

Method

public long contentLength() throws IOException

返回数据长度。

Returns

Type

Description

long

数据长度,单位:byte。

Throws

Name

Description

IOException

如果在此过程中发生IOException将抛出异常。

[h2]contentType

Method

public abstract String contentType()

获取网络数据的编码类型。

Returns

Type

Description

String

网络数据的编码类型。

[h2]isDuplex

Method

public boolean isDuplex()

是否开启全双工请求模式,默认不开启。若您开启全双工模式,您需要重写此方法,以返回正确的值,并重写writeTo方法,且不应设置网络请求的超时时间。

Returns

Type

Description

boolean

是否开启全双工请求模式,默认值为false。

  • true:开启全双工请求。若开启,仅HTTP/2协议生效
  • false:不开启全双工请求

[h2]writeTo

Method

public abstract void writeTo(OutputStream outputStream) throws IOException

将请求体数据写到输出流。若您需要开启全双工模式,需要服务器同样支持全双工模式,并重写此方法。可以将请求返回的数据放到其他线程进行写入,以保证此方法可以快速返回,并重写isDuplex方法,返回正确的值,且不应设置网络请求的超时时间。

Parameters

Name

Description

outputStream

输出流。

Throws

Name

Description

IOException

如果在此过程中发生IOException将抛出异常。