diff --git a/modules/@angular/http/src/body.ts b/modules/@angular/http/src/body.ts index babd1e59c7..02375a73e5 100644 --- a/modules/@angular/http/src/body.ts +++ b/modules/@angular/http/src/body.ts @@ -49,6 +49,10 @@ export abstract class Body { return String.fromCharCode.apply(null, new Uint16Array(this._body)); } + if (this._body === null) { + return ''; + } + if (isJsObject(this._body)) { return Json.stringify(this._body); } diff --git a/modules/@angular/http/test/static_request_spec.ts b/modules/@angular/http/test/static_request_spec.ts index 9c0f4db0f6..5d8262d42a 100644 --- a/modules/@angular/http/test/static_request_spec.ts +++ b/modules/@angular/http/test/static_request_spec.ts @@ -77,5 +77,16 @@ export function main() { expect(req.detectContentType()).toEqual(ContentType.BLOB); }); }); + + it('should return empty string if no body is present', () => { + const req = new Request(new RequestOptions({ + url: 'test', + method: 'GET', + body: null, + headers: new Headers({'content-type': 'application/json'}) + })); + + expect(req.text()).toEqual(''); + }); }); }