angular-cn/public/docs/js/latest/api/http/Response-class.jade

226 lines
3.3 KiB
Plaintext
Raw Normal View History

p.location-badge.
exported from <a href='../http'>angular2/http</a>
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/http/static_response.ts#L6-L116">angular2/src/http/static_response.ts (line 6)</a>
:markdown
Creates `Response` instances from provided values.
Though this object isn't
usually instantiated by end-users, it is the primary object interacted with when it comes time to
add data to a view.
#Example
```
http.request('my-friends.txt').toRx().subscribe(response => this.friends = response.text());
```
The Response's interface is inspired by the Response constructor defined in the [Fetch
Spec](https://fetch.spec.whatwg.org/#response-class), 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.
.l-main-section
h2 Members
.l-sub-section
h3#constructor constructor
pre.prettyprint
code.
constructor(responseOptions: ResponseOptions)
:markdown
.l-sub-section
h3#type type
:markdown
One of "basic", "cors", "default", "error, or "opaque".
Defaults to "default".
.l-sub-section
h3#ok ok
:markdown
True if the response's status is within 200-299
.l-sub-section
h3#url url
:markdown
URL of response.
Defaults to empty string.
.l-sub-section
h3#status status
:markdown
Status code returned by server.
Defaults to 200.
.l-sub-section
h3#statusText statusText
:markdown
Text representing the corresponding reason phrase to the `status`, as defined in [ietf rfc 2616
section 6.1.1](https://tools.ietf.org/html/rfc2616#section-6.1.1)
Defaults to "OK"
.l-sub-section
h3#bytesLoaded bytesLoaded
:markdown
Non-standard property
Denotes how many of the response body's bytes have been loaded, for example if the response is
the result of a progress event.
.l-sub-section
h3#totalBytes totalBytes
:markdown
Non-standard property
Denotes how many bytes are expected in the final response body.
.l-sub-section
h3#headers headers
:markdown
Headers object based on the `Headers` class in the [Fetch
Spec](https://fetch.spec.whatwg.org/#headers-class).
.l-sub-section
h3#blob blob
pre.prettyprint
code.
blob()
:markdown
Not yet implemented
.l-sub-section
h3#json json
pre.prettyprint
code.
json()
:markdown
Attempts to return body as parsed `JSON` object, or raises an exception.
.l-sub-section
h3#text text
pre.prettyprint
code.
text()
:markdown
Returns the body as a string, presuming `toString()` can be called on the response body.
.l-sub-section
h3#arrayBuffer arrayBuffer
pre.prettyprint
code.
arrayBuffer()
:markdown
Not yet implemented