HttpRequest
一个外发的 HTTP 请求,带有一个可选的类型化的请求体(body
)。
An outgoing HTTP request with an optional typed body.
class HttpRequest<T> {
constructor(method: string, url: string, third?: T | { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; }, fourth?: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; })
body: T | null
headers: HttpHeaders
reportProgress: boolean
withCredentials: boolean
responseType: 'arraybuffer' | 'blob' | 'json' | 'text'
method: string
params: HttpParams
urlWithParams: string
url: string
serializeBody(): ArrayBuffer | Blob | FormData | string | null
detectContentTypeHeader(): string | null
clone(update: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; body?: any; method?: string; url?: string; setHeaders?: { ...; }; setParams?: { ...; }; } = {}): HttpRequest<any>
}
说明
HttpRequest
表示一个外发请求,包括 URL、方法、请求头、请求体和其它请求配置项。 它的实例都是不可变的。要修改 HttpRequest
,应该使用 clone
方法。
HttpRequest
represents an outgoing request, including URL, method, headers, body, and other request configuration options. Instances should be assumed to be immutable. To modify a HttpRequest
, the clone
method should be used.
构造函数
3 个重载形式...显示所有 隐藏所有 expand_moreOverload #1
参数
Overload #2
参数
Overload #3
参数
|
属性
属性 | 说明 |
---|---|
body: T | null | 只读 请求体,如果没有则为 The request body, or 请求体无法确保自己是不可变的,因为它们可以包含指向任何自定义数据类型的引用。 不过,在拦截器中,要小心维护其幂等性 —— 把它们当做不可变对象。 Bodies are not enforced to be immutable, as they can include a reference to any user-defined data type. However, interceptors should take care to preserve idempotence by treating them as such. |
headers: HttpHeaders | 只读 本请求的外发请求头。 Outgoing headers for this request. |
reportProgress: boolean | 只读 该请求是否应该暴露出进度事件。 Whether this request should be made in a way that exposes progress events. 进度事件很昂贵(在每个事件中都会执行一次变更检测),所以只有当消费者关心这些事件时才应该请求这些进度事件。 Progress events are expensive (change detection runs on each event) and so they should only be requested if the consumer intends to monitor them. |
withCredentials: boolean | 只读 此请求是否应该带着凭证(Cookie)一起外发。 Whether this request should be sent with outgoing credentials (cookies). |
responseType: 'arraybuffer' | 'blob' | 'json' | 'text' | 只读 所期待的服务器响应类型。 The expected response type of the server. 它用来在把响应对象返回给被请求者之前以恰当的方式解析它。 This is used to parse the response appropriately before returning it to the requestee. |
method: string | 只读 外发 HTTP 请求的方法。 The outgoing HTTP request method. |
params: HttpParams | 只读 外发的 URL 参数。 Outgoing URL parameters. |
urlWithParams: string | 只读 外发的 URL,及其所有 URL 参数。 The outgoing URL with all URL parameters set. |
url: string | 只读 声明于构造函数中 |
方法
把无格式的请求体转换成适合传给服务器的序列化格式。 Transform the free-form body into a serialized format suitable for transmission to the server. |
参数没有参数。 返回值
|
检测请求体,并尝试给它推断出一个合适的 MIME 类型。 Examine the body and attempt to infer an appropriate MIME type for it. |
参数没有参数。 返回值
|
如果没有合适的 MIME 类型,该方法就会返回 If no such type can be inferred, this method will return |
3 个重载形式...显示所有 隐藏所有 expand_moreOverload #1Overload #2
参数
返回值Overload #3
参数
返回值
|