Headers
Polyfill for Headers, as specified in the Fetch Spec.
已弃用: see https://angular.io/guide/http
class Headers {
static fromResponseHeaderString(headersString: string): Headers
constructor(headers?: Headers | { [name: string]: any; })
append(name: string, value: string): void
delete(name: string): void
forEach(fn: (values: string[], name: string, headers: any) => void): void
get(name: string): string | null
has(name: string): boolean
keys(): string[]
set(name: string, value: string | string[]): void
values(): string[][]
toJSON(): {...}
getAll(name: string): string[] | null
entries()
}
说明
The only known difference between this Headers
implementation and the spec is the lack of an entries
method.
静态方法
Returns a new Headers instance from the given DOMString of Response Headers |
构造函数
方法
Appends a header to existing list of header values for a given header name. |
Deletes all header values for the given name. |
Returns first header that matches given name. |
Checks for existence of header by given name. |
Returns the names of the headers |
Sets or overrides header value for given name. |
Returns values of all headers. |
参数没有参数。 返回值
|
Returns string of all headers. |
参数没有参数。 返回值`{ }` |
Returns list of header values for a given name. |
This method is not implemented. |
参数没有参数。 |
使用说明
Example
- import {Headers} from '@angular/http';
-
- var firstHeaders = new Headers();
- firstHeaders.append('Content-Type', 'image/jpeg');
- console.log(firstHeaders.get('Content-Type')) //'image/jpeg'
-
- // Create headers from Plain Old JavaScript Object
- var secondHeaders = new Headers({
- 'X-My-Custom-Header': 'Angular'
- });
- console.log(secondHeaders.get('X-My-Custom-Header')); //'Angular'
-
- var thirdHeaders = new Headers(secondHeaders);
- console.log(thirdHeaders.get('X-My-Custom-Header')); //'Angular'