填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

TestRequest

已收到并准备好进行应答的模拟请求。

A mock requests that was received and is ready to be answered.

查看"说明"...

      
      class TestRequest {
  constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
  cancelled: boolean
  request: HttpRequest<any>
  flush(body: string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
  error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
  event(event: HttpEvent<any>): void
}
    

说明

此接口允许访问底层 HttpRequest,并允许使用 HttpEventHttpErrorResponse 进行响应。

This interface allows access to the underlying HttpRequest, and allows responding with HttpEvents or HttpErrorResponses.

构造函数

      
      constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
    
参数
request HttpRequest
observer Observer>

属性

属性说明
cancelled: boolean只读

请求在发送后是否已被取消。

Whether the request was cancelled after it was sent.

request: HttpRequest<any>声明在构造函数中

方法

通过返回 body 以及其他 HTTP 信息(例如响应标头)(如果提供过)来解析请求。如果请求指定了预期的 body 类型,则将 body 转换为所请求的类型。否则,body 在默认情况下转换成 JSON

Resolve the request by returning a body plus additional HTTP information (such as response headers) if provided. If the request specifies an expected body type, the body is converted into the requested type. Otherwise, the body is converted to JSON by default.

      
      flush(body: string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
    
参数
body string | number | boolean | Object | ArrayBuffer | Blob | (string | number | boolean | Object)[]
opts object
可选. 默认值是 `{}`.
返回值

void

成功和失败的响应都可以通过 flush() 传递。

Both successful and unsuccessful responses can be delivered via flush().

通过返回 ErrorEvent (例如,模拟网络故障)来解决请求。

Resolve the request by returning an ErrorEvent (e.g. simulating a network failure).

      
      error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
    
参数
error ErrorEvent
opts object
可选. 默认值是 `{}`.
返回值

void

在响应流上为此请求传递一个任意的 HttpEvent

Deliver an arbitrary HttpEvent (such as a progress event) on the response stream for this request.

      
      event(event: HttpEvent<any>): void
    
参数
event HttpEvent
返回值

void