## Request
Creates Request instances from provided values.
The Request's interface is inspired by the Request constructor defined in the Fetch Spec, but is considered a static value whose body can be accessed many times. There are other differences in the implementation, but this is the most significant.
`Request` instances are typically created by higher-level classes, like `Http` and `Jsonp`, but it may occasionally be useful to explicitly create Request instances. One such example is when creating services that wrap higher-level services, like `Http`, where it may be useful to generate a Request with arbitrary headers and search params.
```typescript
import {Injectable, Injector} from '@angular/core';
import {HTTP_PROVIDERS, Http, Request, RequestMethod} from '@angular/http';
@Injectable()
class AutoAuthenticator {
constructor(public http:Http) {}
request(url:string) {
return this.http.request(new Request({
method: RequestMethod.Get,
url: url,
search: 'password=123'
}));
}
}
var injector = Injector.resolveAndCreate([HTTP_PROVIDERS, AutoAuthenticator]);
var authenticator = injector.get(AutoAuthenticator);
authenticator.request('people.json').subscribe(res => {
//URL should have included '?password=123'
console.log('people', res.json());
});
```
### 类定义
```typescript
class Request extends Body {
constructor(requestOptions: RequestArgs)
method : RequestMethod
headers : Headers
url : string
withCredentials : boolean
responseType : ResponseContentType
detectContentType() : ContentType
detectContentTypeFromBody() : ContentType
getBody() : any
}
```
### 属性
- method : `RequestMethod`
Http method with which to perform the request.
- headers : `Headers`
- url : `string`
- withCredentials : `boolean` Enable use credentials
- responseType : `ResponseContentType` Buffer to store the response
- detectContentType() : `ContentType` Returns the content type enum based on header options.
- detectContentTypeFromBody() : `ContentType` Returns the content type of request's body based on its type.
- getBody() : `any` Returns the request's body according to its type. If body is undefined, return null.
- 说明
- angular 1.x
- ngModelController
- ngOptions
- ngModelOptions
- lifecycle
- directive
- angular 2
- @angular/forms
- 类
- AbstractControl
- AbstractControlDirective
- AbstractFormGroupDirective
- FormControl
- FormArray
- FormBuilder
- FormGroup
- NgControl
- 接口
- controlValueAccessor
- 指令
- DefaultValueAccessor
- Angular 2 生命周期
- OnInit
- DoCheck
- @angular/router
- 配置
- Routes
- 指令
- RouterOutlet
- RouterLink
- 接口
- ActivatedRoute
- UrlTree
- NavigationExtras
- ActivatedRouteSnapshot
- RouterStateSnapshot
- 类
- UrlSegment
- UrlSegmentGroup
- UrlSerializer
- DefaultUrlSerializer
- Router
- bug记得
- @angular/http
- 类
- Http
- Body
- Response
- ResponseOptions
- Header
- Request
- RequestOptions
- URLSearchParams
- @angular/core
- decorator
- Component-decorator
- animation
- DI
- linker
- TemplateRef
- ElementRef
- EmbeddedViewRef
- ViewRef
- ViewContainerRef
- Query
- ComponentFactory
- ComponentRef
- Renderer
- change_detection
- KeyValueDiffers
- IterableDiffers
- ChangeDetectorRef
- ChangeDetectionStrategy
- Zone
- ngZone
- @angular/common
- 指令
- NgTemplateOutlet
- QueryList
- bootstrap4
- card
- form
- 重点关注博客
- 学习过的文章
- 笔记
- Angular 2 双向绑定
- 将字符串解析成DOM
- rx相关
- operators
- combineLatest
- combineAll
- concat(All, Map, *MapTo)
- 背压(backpressure)
- js事件keycode对应表
- 装饰器
- 有用的代码摘录
- 日期操作
- 数量操作
- 字符操作
- rxjs问题
- 小示例
- h5面试准备
- react
- 开发遇到的问题