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

static fromResponseHeaderString(headersString: string): Headers
      
      static fromResponseHeaderString(headersString: string): Headers
    
参数
headersString string
返回值

Headers

构造函数

constructor(headers?: Headers | { [name: string]: any; })
      
      constructor(headers?: Headers | { [name: string]: any; })
    
参数
headers Headers | { [name: string]: any; }

可选. 默认值是 undefined.

方法

Appends a header to existing list of header values for a given header name.

append(name: string, value: string): void
      
      append(name: string, value: string): void
    
参数
name string
value string
返回值

void

Deletes all header values for the given name.

delete(name: string): void
      
      delete(name: string): void
    
参数
name string
返回值

void

forEach(fn: (values: string[], name: string, headers: any) => void): void
      
      forEach(fn: (values: string[], name: string, headers: any) => void): void
    
参数
fn (values: string[], name: string, headers: any) => void
返回值

void

Returns first header that matches given name.

get(name: string): string | null
      
      get(name: string): string | null
    
参数
name string
返回值

string | null

Checks for existence of header by given name.

has(name: string): boolean
      
      has(name: string): boolean
    
参数
name string
返回值

boolean

Returns the names of the headers

keys(): string[]
      
      keys(): string[]
    
参数

没有参数。

返回值

string[]

Sets or overrides header value for given name.

set(name: string, value: string | string[]): void
      
      set(name: string, value: string | string[]): void
    
参数
name string
value string | string[]
返回值

void

Returns values of all headers.

values(): string[][]
      
      values(): string[][]
    
参数

没有参数。

返回值

string[][]

Returns string of all headers.

toJSON(): { [name: string]: any; }
      
      toJSON(): {
    [name: string]: any;
}
    
参数

没有参数。

返回值

`{

}`

Returns list of header values for a given name.

getAll(name: string): string[] | null
      
      getAll(name: string): string[] | null
    
参数
name string
返回值

string[] | null

This method is not implemented.

entries()
      
      entries()
    
参数

没有参数。

使用说明

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'
      
      
  1. import {Headers} from '@angular/http';
  2.  
  3. var firstHeaders = new Headers();
  4. firstHeaders.append('Content-Type', 'image/jpeg');
  5. console.log(firstHeaders.get('Content-Type')) //'image/jpeg'
  6.  
  7. // Create headers from Plain Old JavaScript Object
  8. var secondHeaders = new Headers({
  9. 'X-My-Custom-Header': 'Angular'
  10. });
  11. console.log(secondHeaders.get('X-My-Custom-Header')); //'Angular'
  12.  
  13. var thirdHeaders = new Headers(secondHeaders);
  14. console.log(thirdHeaders.get('X-My-Custom-Header')); //'Angular'