teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

書式改善

2020/04/29 15:34

投稿

jonason
jonason

スコア8

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,3 @@
1
- やりたいこと
2
- /challengesにPOSTでHTTPリクエストを送信してチャレンジを開始します。
3
- レスポンス中の呼出予定時刻(actives_at)の時刻に/challengesへPUTでHTTPリクエストを送信します。 このときチャレンジID(id)をX-Challenge-Idヘッダに付与する必要があります。
4
- ということをしたいです。
5
1
  現在のコードが
6
2
  const axios = require("axios")
7
3
 

2

書式改善

2020/04/29 15:34

投稿

jonason
jonason

スコア8

title CHANGED
File without changes
body CHANGED
@@ -78,4 +78,35 @@
78
78
  total_diff: 0
79
79
  }
80
80
  undefined
81
- と出てきてしまします。
81
+ と出てきてしまします。
82
+ const axios = require("axios")
83
+
84
+ axios.post("http://challenge.z2o.cloud/challenges?nickname=hoge")
85
+ .then(response => {
86
+ console.log(response.data)
87
+ })
88
+ .catch((error) => console.log(error.message));
89
+
90
+ axios.put('http://challenge.z2o.cloud/', { params: { headers: {'X-Challenge-Id': 'jona0915'} }})
91
+ .then(response => {
92
+ console.log(response.data)
93
+ })
94
+ .catch((error) => console.log(error.message))
95
+ 上のように変えてみたり、
96
+ const axios = require("axios")
97
+
98
+ axios.post("http://challenge.z2o.cloud/challenges?nickname=hoge")
99
+ .then(response => {
100
+ console.log(response.data)
101
+ })
102
+ .catch((error) => console.log(error.message));
103
+
104
+ axios.put('http://challenge.z2o.cloud/', { params: { headers: {'X-Challenge-Id': 'jona0915'}, data: {} }})
105
+ .then(response => {
106
+ console.log(response.data)
107
+ })
108
+ .catch((error) => console.log(error.message))
109
+
110
+ この記事をみて
111
+ https://qiita.com/taikai_m/items/1ec5e4e4b2ccbe8adf76
112
+ data: {} を追加してみても結果は変わらずでした

1

書式改善

2020/04/26 15:24

投稿

jonason
jonason

スコア8

title CHANGED
File without changes
body CHANGED
@@ -52,4 +52,30 @@
52
52
  called_at: 1587905985321,
53
53
  total_diff: 0
54
54
  }
55
- となっているので、PUTの仕方が違うみたいですが、何がどう違うのかがわかりません。
55
+ となっているので、PUTの仕方が違うみたいですが、何がどう違うのかがわかりません。
56
+
57
+ const axios = require("axios")
58
+
59
+ axios.post("http://challenge.z2o.cloud/challenges?nickname=hoge")
60
+ .then(response => {
61
+ console.log(response.data)
62
+ })
63
+ .then((text) => console.log(text))
64
+ .catch((error) => console.log(error.message));
65
+
66
+ axios.put('http://challenge.z2o.cloud/', { headers: {'X-Challenge-Id': 'jona0915'} ,data: {}})
67
+ .then(response => {
68
+ console.log(response.data)
69
+ })
70
+ .catch((error) => console.log(error.message))
71
+ とコードを変えてみましたが、
72
+ $ node index.js
73
+ Request failed with status code 405
74
+ {
75
+ id: 'dKfPN+nYvSIzSRcJn9zU4+rZSbBsc29a61MPDe06V7s2WGypMQAVnE7rD8umKDTs',
76
+ actives_at: 1587909743516,
77
+ called_at: 1587909743189,
78
+ total_diff: 0
79
+ }
80
+ undefined
81
+ と出てきてしまします。