Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 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. }
  47.  
  48.  
  49. }
  50.  
  51. import { Injectable } from '@angular/core';
  52. import { Http, Headers, Response, RequestOptions, RequestMethod } from '@angular/http';
  53. import { Observable } from 'rxjs';
  54. import 'rxjs/add/operator/map'
  55.  
  56. @Injectable()
  57. export class AuthenticationService {
  58. public token: string;
  59.  
  60. constructor(private http: Http) {
  61.  
  62. }
  63.  
  64. login(username: string, password: string): Observable<boolean> {
  65. // let head = new Headers({ 'Content-Type': 'application/json' });
  66. const headers = new Headers();
  67. headers.append('Content-Type', 'application/json');
  68. let options = new RequestOptions({ headers: headers });
  69. return this.http.post('http://localhost:8080/auth', JSON.stringify({ username: username, password: password }),options)
  70. .map((response: Response) => {
  71. // login successful if there's a jwt token in the response
  72. let token = response.json() && response.json().token;
  73. console.log(response);
  74.  
  75. });
  76. }
  77.  
  78.  
  79. }
  80.  
  81. import { Injectable } from '@angular/core';
  82. import { Http, Headers, Response, RequestOptions, RequestMethod } from '@angular/http';
  83. import { Observable } from 'rxjs';
  84. import 'rxjs/add/operator/map'
  85.  
  86. @Injectable()
  87. export class AuthenticationService {
  88. public token: string;
  89.  
  90. constructor(private http: Http) {
  91.  
  92. }
  93.  
  94. login(username: string, password: string): Observable<boolean> {
  95. let head = new Headers({ 'Content-Type': 'application/json' });
  96. let options = new RequestOptions({ headers: head });
  97. return this.http.post('http://localhost:8080/auth', JSON.stringify({ username: username, password: password }),options)
  98. .map((response: Response) => {
  99. // login successful if there's a jwt token in the response
  100. let token = response.json() && response.json().token;
  101. console.log(response);
  102.  
  103. });
  104. }
  105.  
  106.  
  107. }
  108.  
  109. let headers = new Headers({ 'Content-Type': 'application/json' });
  110. headers.append('Accept', 'application/json');
  111. let options = new RequestOptions({ headers: headers });
  112.  
  113. return this.http.post('http://localhost:8080/auth', JSON.stringify({ username: username, password: password }), options)
  114. .map((response: Response) => {
  115. // login successful if there's a jwt token in the response
  116. let token = response.json() && response.json().token;
  117. console.log(response);
  118. });
  119.  
  120. // app.module.ts:
  121.  
  122. import {NgModule} from '@angular/core';
  123. import {BrowserModule} from '@angular/platform-browser';
  124.  
  125. // Import HttpClientModule from @angular/common/http
  126. import {HttpClientModule} from '@angular/common/http';
  127.  
  128. @NgModule({
  129. imports: [
  130. BrowserModule,
  131. // Include it under 'imports' in your application module
  132. // after BrowserModule.
  133. HttpClientModule,
  134. ],
  135. })
  136. export class MyAppModule {}
  137.  
  138. constructor(private http: HttpClient) {}
  139.  
  140. login(username: string, password: string): Observable<boolean> {
  141. return this.http.post('http://localhost:8080/auth', JSON.stringify({ username: username, password: password }))
  142. .map((response: Response) => {
  143. // login successful if there's a jwt token in the response
  144. let token = response.json() && response.json().token;
  145. console.log(response);
  146. });
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement