RequestOptions

Creates a request options object to be optionally provided when instantiating a Request.

查看"说明"...

已弃用: see https://angular.io/guide/http

      
      class RequestOptions {
  constructor(opts: RequestOptionsArgs = {})
  method: RequestMethod | string | null
  headers: Headers | null
  body: any
  url: string | null
  params: URLSearchParams
  search: URLSearchParams
  withCredentials: boolean | null
  responseType: ResponseContentType | null
  merge(options?: RequestOptionsArgs): RequestOptions
}
    

说明

This class is based on the RequestInit description in the Fetch Spec.

All values are null by default. Typical defaults can be found in the BaseRequestOptionsclass, which sub-classes RequestOptions.

import {RequestOptions, Request, RequestMethod} from '@angular/http'; const options = new RequestOptions({ method: RequestMethod.Post, url: 'https://google.com' }); const req = new Request(options); console.log('req.method:', RequestMethod[req.method]); // Post console.log('options.url:', options.url); // https://google.com
      
      import {RequestOptions, Request, RequestMethod} from '@angular/http';

const options = new RequestOptions({
  method: RequestMethod.Post,
  url: 'https://google.com'
});
const req = new Request(options);
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // https://google.com
    

构造函数

constructor(opts: RequestOptionsArgs = {})
      
      constructor(opts: RequestOptionsArgs = {})
    
参数
opts RequestOptionsArgs

可选. 默认值是 {}.

属性

属性说明
method: RequestMethod | string | null

Http method with which to execute a Request. Acceptable methods are defined in the RequestMethodenum.

headers: Headers | null Headers

to be attached to a Request.

body: any

Body to be used when creating a Request.

url: string | null

Url with which to perform a Request.

params: URLSearchParams

Search parameters to be included in a Request.

search: URLSearchParams
withCredentials: boolean | null

Enable use credentials for a Request.

responseType: ResponseContentType | null

方法

Creates a copy of the RequestOptions instance, using the optional input as values to override existing values. This method will not change the values of the instance on which it is being called.

      
      merge(options?: RequestOptionsArgs): RequestOptions
    
参数
options RequestOptionsArgs

可选. 默认值是 undefined.

返回值

RequestOptions

Note that headers and search will override existing values completely if present in the options object. If these values should be merged, it should be done prior to calling merge on the RequestOptions instance.

import {RequestOptions, Request, RequestMethod} from '@angular/http'; const options = new RequestOptions({ method: RequestMethod.Post }); const req = new Request(options.merge({ url: 'https://google.com' })); console.log('req.method:', RequestMethod[req.method]); // Post console.log('options.url:', options.url); // null console.log('req.url:', req.url); // https://google.com
      
      import {RequestOptions, Request, RequestMethod} from '@angular/http';

const options = new RequestOptions({
  method: RequestMethod.Post
});
const req = new Request(options.merge({
  url: 'https://google.com'
}));
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // null
console.log('req.url:', req.url); // https://google.com