diff options
-rw-r--r-- | src/app/shared/services/httpUtil/http-util.service.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/app/shared/services/httpUtil/http-util.service.ts b/src/app/shared/services/httpUtil/http-util.service.ts index 688f3ea..fc9c327 100644 --- a/src/app/shared/services/httpUtil/http-util.service.ts +++ b/src/app/shared/services/httpUtil/http-util.service.ts @@ -26,23 +26,28 @@ import { Http, Response, Headers, RequestOptions } from '@angular/http'; @Injectable() export class HttpUtilService { - headers: Headers; + headersGET: Headers; + headersPOST: Headers; options: RequestOptions private username = require('../../../../cdt.application.properties.json').username; private password = require('../../../../cdt.application.properties.json').password; constructor(private http: Http) { - this.headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersGET = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersPOST = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersPOST.append('Authorization', 'Basic ' + btoa(this.username + ':' + this.password)); } get(req) { + this.options = new RequestOptions({ headers: this.headersGET }); + return this .http .get(req.url, this.options) .map((res: Response) => res.json()) } post(req) { - this.headers.append('Authorization', 'Basic ' + btoa(this.username + ':' + this.password)); - this.options = new RequestOptions({ headers: this.headers }); + + this.options = new RequestOptions({ headers: this.headersPOST }); return this .http @@ -50,4 +55,4 @@ export class HttpUtilService { .map((res: Response) => res.json()) } -}
\ No newline at end of file +} |