BaseRequestOptions
Subclass of RequestOptions, with default values.
已弃用: see https://angular.io/guide/http
class BaseRequestOptions extends RequestOptions {
// 继承自 http/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
}
说明
Default values:
- method: RequestMethod.Get
- headers: empty
Headersobject
This class could be extended and bound to the RequestOptionsclass when configuring an Injector, in order to override the default options used by Httpto create and send Requests.
import {BaseRequestOptions, RequestOptions} from '@angular/http';
class MyOptions extends BaseRequestOptions {
search: string = 'coreTeam=true';
}
{provide: RequestOptions, useClass: MyOptions};
The options could also be extended when manually creating a Requestobject.
import {BaseRequestOptions, Request, RequestMethod} from '@angular/http';
const options = new BaseRequestOptions();
const req = new Request(options.merge({
method: RequestMethod.Post,
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