質問編集履歴

15

質問文の修正

2020/11/12 09:21

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -12,9 +12,9 @@
12
12
 
13
13
  headerの情報が取得できないです。
14
14
 
15
- "const token = res.headers.get('access_token')"といったコードを書いたのですが、値がNULLとなってしまいます。
15
+ "const token = res.headers.get('access_token')"といったコードを書いたのですが、値が未定義となってしまいます。
16
16
 
17
- ですがresponse headerにはaccess_tokenという名前でtokenが定義されています。どうして取得しようとするとNULLになってしまい、取得ができないのか
17
+ ですがresponse headerにはaccess_tokenという名前でtokenが定義されています。どうして取得しようとすると未定義になってしまい、取得ができないのか
18
18
 
19
19
 
20
20
 
@@ -28,21 +28,13 @@
28
28
 
29
29
  ).subscribe(res => {
30
30
 
31
-
31
+ let response: any = res;
32
32
 
33
33
 
34
34
 
35
- const token = res.headers.get('accsess_token')
35
+ const token = response.access_token
36
36
 
37
37
  this.cookieService.set('access_token', token);
38
-
39
- console.log(token)
40
-
41
- this.cookieService.set('access_token', token);
42
-
43
- console.log(document.cookie)
44
-
45
-
46
38
 
47
39
 
48
40
 
@@ -68,21 +60,15 @@
68
60
 
69
61
 
70
62
 
63
+ return response()->json([
71
64
 
65
+ 'access_token' => $token,
72
66
 
73
- return response($token_encode)
67
+ 'token_type' => 'bearer',
74
68
 
75
- ->header('access_token', $token_encode)
69
+ 'expires_in' => auth()->factory()->getTTL() * 60
76
70
 
77
- ->header('Cache-Control','no-cache')
78
-
79
- ->cookie('access_token',$token_encode,null,null,null,null,false)
80
-
81
- ->header('Content-Type', 'bearerapplication/json');
82
-
83
-
84
-
85
- }
71
+ ]);
86
72
 
87
73
  ```
88
74
 

14

質問文の加筆

2020/11/12 09:21

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -28,11 +28,11 @@
28
28
 
29
29
  ).subscribe(res => {
30
30
 
31
- let response: any = res;
31
+
32
32
 
33
33
 
34
34
 
35
- const token = response.headers.get('accsess_token')
35
+ const token = res.headers.get('accsess_token')
36
36
 
37
37
  this.cookieService.set('access_token', token);
38
38
 

13

質問文の修正

2020/11/12 08:04

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -12,9 +12,9 @@
12
12
 
13
13
  headerの情報が取得できないです。
14
14
 
15
- "const token = res.headers.get('access_token')"といったコードを書いたのですが、値が取得されずに未定義となってしまいます。
15
+ "const token = res.headers.get('access_token')"といったコードを書いたのですが、値がNULLとなってしまいます。
16
16
 
17
- ですがresponse headerにはaccess_tokenという名前でtokenが定義されています。どうして取得しようとすると未定義になってしまい、取得ができないのか
17
+ ですがresponse headerにはaccess_tokenという名前でtokenが定義されています。どうして取得しようとするとNULLになってしまい、取得ができないのか
18
18
 
19
19
 
20
20
 
@@ -24,19 +24,29 @@
24
24
 
25
25
  ```typescript
26
26
 
27
- this.http.post(`http://localhost:8000/api/login/`, body, { observe: 'response'
27
+ this.http.post(`http://localhost:8000/api/login/`, body, { observe: 'response' },
28
28
 
29
29
  ).subscribe(res => {
30
30
 
31
-
31
+ let response: any = res;
32
32
 
33
+
34
+
33
- const token = res.headers.get('access_token') //ここが今回のheader情報の取得したいコード
35
+ const token = response.headers.get('accsess_token')
36
+
37
+ this.cookieService.set('access_token', token);
34
38
 
35
39
  console.log(token)
36
40
 
37
41
  this.cookieService.set('access_token', token);
38
42
 
39
43
  console.log(document.cookie)
44
+
45
+
46
+
47
+
48
+
49
+ });
40
50
 
41
51
  ```
42
52
 

12

質問文の修正

2020/11/12 07:51

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  ```PHP
44
44
 
45
- function function login() {
45
+ function login() {
46
46
 
47
47
  $credentials = request(['email', 'password']);
48
48
 
@@ -58,17 +58,21 @@
58
58
 
59
59
 
60
60
 
61
- return response()->json([
62
-
63
- 'access_token' => $token,
64
-
65
- 'token_type' => 'bearer',
66
-
67
- 'expires_in' => auth()->factory()->getTTL() * 60
68
-
69
- ]);
70
61
 
71
62
 
63
+ return response($token_encode)
64
+
65
+ ->header('access_token', $token_encode)
66
+
67
+ ->header('Cache-Control','no-cache')
68
+
69
+ ->cookie('access_token',$token_encode,null,null,null,null,false)
70
+
71
+ ->header('Content-Type', 'bearerapplication/json');
72
+
73
+
74
+
75
+ }
72
76
 
73
77
  ```
74
78
 

11

質問文の修正

2020/11/12 07:43

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  "const token = res.headers.get('access_token')"といったコードを書いたのですが、値が取得されずに未定義となってしまいます。
16
16
 
17
- ですがheaderにはaccess_tokenという名前で定義されています。どうして取得しようとすると未定義になってしまでしょう
17
+ ですがresponse headerにはaccess_tokenという名前でtokenが定義されています。どうして取得しようとすると未定義になってしまい、取得ができないのか
18
18
 
19
19
 
20
20
 

10

タイトルの変更

2020/11/12 07:10

投稿

sagitarou
sagitarou

スコア7

test CHANGED
@@ -1 +1 @@
1
- headerの情報が取得できない
1
+ ブラウザのresponse headerの情報が取得できない
test CHANGED
File without changes

9

質問文の加筆

2020/11/12 06:56

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,11 @@
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
- headerの情報が取得できないです。未定義となってしまいます。
13
+ headerの情報が取得できないです。
14
14
 
15
+ "const token = res.headers.get('access_token')"といったコードを書いたのですが、値が取得されずに未定義となってしまいます。
16
+
15
- ですがheaderには定義されています。どうとなのでしょうか
17
+ ですがheaderにはaccess_tokenという名前で定義されています。どうして取得しようとすると未定義にってしまうのでしょうか
16
18
 
17
19
 
18
20
 

8

質問文のコードの修正

2020/11/12 06:47

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  ```PHP
42
42
 
43
- function login() {
43
+ function function login() {
44
44
 
45
45
  $credentials = request(['email', 'password']);
46
46
 
@@ -56,19 +56,17 @@
56
56
 
57
57
 
58
58
 
59
- return response($token_encode)
59
+ return response()->json([
60
60
 
61
- ->header('access_token', $token_encode)
61
+ 'access_token' => $token,
62
62
 
63
- ->header('Cache-Control','no-cache')
63
+ 'token_type' => 'bearer',
64
64
 
65
- ->cookie('access_token',$token,null,null,null,null,false)
65
+ 'expires_in' => auth()->factory()->getTTL() * 60
66
66
 
67
- ->header('Content-Type', 'bearerapplication/json');
67
+ ]);
68
68
 
69
-
70
69
 
71
- }
72
70
 
73
71
  ```
74
72
 

7

質問文の修正

2020/11/12 06:17

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,9 @@
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
- headerの情報が取得できないです。
13
+ headerの情報が取得できないです。未定義となってしまいます。
14
14
 
15
- コードの書き方間違っているのか、何かしらの設ができていなか、どこがおかいの質問したいです
15
+ ですheaderには義されています。どういうことなのょう
16
16
 
17
17
 
18
18
 
@@ -78,7 +78,7 @@
78
78
 
79
79
 
80
80
 
81
- headerのConnectionがcloseとはなっていてそれが原因なのかと思ったのですが、keep-activeにする方法がわかりませんでした
81
+
82
82
 
83
83
 
84
84
 

6

2020/11/12 06:01

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -91,5 +91,3 @@
91
91
  フロントエンド: angular
92
92
 
93
93
  バックエンド: laravel
94
-
95
- で作成しました

5

質問文の修正

2020/11/11 01:13

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  ```typescript
24
24
 
25
- this.http.post(`http://localhost:8000/api/login/`, body, { observe: 'response', headers: { 'Content-Type': 'application/json' } },
25
+ this.http.post(`http://localhost:8000/api/login/`, body, { observe: 'response'
26
26
 
27
27
  ).subscribe(res => {
28
28
 

4

質問文の修正

2020/11/08 14:35

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- POSTリクエストを送ったさいのリクエストheaderから特定の情報だけを抜き取れるようにしたいです。
5
+ POSTリクエストを送ったさいのリクエストheaderから特定のheader情報だけを抜き取れるようにしたいです。
6
6
 
7
7
 
8
8
 

3

質問文の修正

2020/11/08 13:44

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  headerの情報が取得できないです。
14
14
 
15
- コードの書き方が間違っているのか、何かしらの設定ができていないのかわからないのでどこがおかしいのか質問したいです
15
+ コードの書き方が間違っているのか、何かしらの設定ができていないのかどこがおかしいのか質問したいです
16
16
 
17
17
 
18
18
 

2

質問文の修正

2020/11/08 12:06

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -78,7 +78,7 @@
78
78
 
79
79
 
80
80
 
81
- headerのConnectionがcloseとはなっていてそれが原因なのかと思ったのですが、keep-activeにする方法がわかりませんでした
81
+ headerのConnectionがcloseとはなっていてそれが原因なのかと思ったのですが、keep-activeにする方法がわかりませんでした
82
82
 
83
83
 
84
84
 

1

質問文の修正

2020/11/08 11:43

投稿

sagitarou
sagitarou

スコア7

test CHANGED
File without changes
test CHANGED
@@ -78,6 +78,10 @@
78
78
 
79
79
 
80
80
 
81
+ headerのConnectionがcloseとはなっていてそれが原因なのかと思ったのですが、keep-activeにする方法がわかりませんでした。
82
+
83
+
84
+
81
85
 
82
86
 
83
87
  ### 補足情報(FW/ツールのバージョンなど)