Guest User

Untitled

a guest
Oct 24th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. {
  2. "/api/*":{
  3.  
  4. "target":"http://10.104.40.14:8290/my_app",
  5. "secure":false,
  6. "logLevel":"debug"
  7. }
  8. }
  9.  
  10. zone.js:2933 POST http://localhost:4200/api/security/login 401 (Unauthorized)
  11. <html>
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  14. <title>Error 401 Unauthorized</title>
  15. </head>
  16. <body><h2>HTTP ERROR 401</h2>
  17. <p>Problem accessing /de_prp/error. Reason:
  18. <pre> Unauthorized</pre></p>
  19. </body>
  20. </html>
  21.  
  22. import { Injectable, OnInit } from '@angular/core';
  23.  
  24. import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
  25. import { RequestOptions, Headers } from '@angular/http';
  26. import { URLSearchParams } from '@angular/http';
  27. @Injectable()
  28. export class AuthService implements OnInit {
  29. constructor(private http: HttpClient) { }
  30.  
  31. ngOnInit(): void {
  32.  
  33. }
  34.  
  35.  
  36. login(username, password, rememberMe) {
  37. console.log(username, password, rememberMe);
  38.  
  39. //const headers = new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8');
  40. const body = JSON.stringify({ username: username, password: password });
  41. const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
  42. this.http.post("/api/security/login", body, { headers: headers }).subscribe(
  43. res => {
  44. console.log(res);
  45. },
  46. (err: HttpErrorResponse) => {
  47.  
  48. console.log(err.error);
  49. console.log(err.name);
  50. console.log(err.message);
  51. console.log(err.status);
  52. }
  53. )
  54. }
  55. logout() {
  56.  
  57. this.http.get("/api/auth/logout").subscribe(
  58. res => {
  59. console.log(res);
  60. },
  61. (err: HttpErrorResponse) => {
  62.  
  63. console.log(err.error);
  64. console.log(err.name);
  65. console.log(err.message);
  66. console.log(err.status);
  67. }
  68. );
  69. }
  70. }
Add Comment
Please, Sign In to add comment