Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. POST /auth HTTP/1.1
  2. Host: localhost:8080
  3. Connection: keep-alive
  4. Content-Length: 39
  5. Pragma: no-cache
  6. Cache-Control: no-cache
  7. Accept: application/json, text/plain, */*
  8. Origin: http://localhost:4200
  9. User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
  10. content-type: text/plain
  11. Referer: http://localhost:4200/login
  12. Accept-Encoding: gzip, deflate, br
  13. Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
  14.  
  15. Accept:*/*
  16. Accept-Encoding:gzip, deflate, sdch, br
  17. Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
  18. Access-Control-Request-Headers:content-type
  19. Access-Control-Request-Method:POST
  20. Cache-Control:no-cache
  21. .
  22. .
  23.  
  24. import { Injectable } from '@angular/core';
  25. import { Http, Headers, Response, RequestOptions, RequestMethod } from '@angular/http';
  26. import { Observable } from 'rxjs';
  27. import 'rxjs/add/operator/map'
  28.  
  29. @Injectable()
  30. export class AuthenticationService {
  31. public token: string;
  32.  
  33. constructor(private http: Http) {
  34.  
  35. }
  36.  
  37. login(username: string, password: string): Observable<boolean> {
  38. let head = new Headers({ 'Content-Type': 'application/json' });
  39. return this.http.post('http://localhost:8080/auth', JSON.stringify({ username: username, password: password }),{ headers: head})
  40. .map((response: Response) => {
  41. // login successful if there's a jwt token in the response
  42. let token = response.json() && response.json().token;
  43. console.log(response);
  44.  
  45. });
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement