- Published on
express.jsで"Cannot POST"(Cannot GET)となってしまう以外な原因
- Authors
- Name
- Shou Arisaka / 有坂翔
Node.jsプログラミング言語のHTTP/HTTPSウェブサーバーのパッケージライブラリ、"express.js"において、"Cannot POST"(Cannot GET)エラーが出てしまう場合の対処方法と対策方法、原因についてです。
以下のようにres.send()
で返り値を指定していない状態であると、httpリクエストをした際にCannot POST
エラーとなります。
app.all('/configall', function (req, res, next) {
console.log('Accessing the secret section ...')
next() // pass control to the next handler
})
curl http://192.168.0.110:8111/configall
res.send()
をどこかに書いてあげればよいです。エラーがちょっとわかりにくいですね。
app.all('/configall', function (req, res, next) {
console.log('Accessing the secret section ...')
res.send("something here.")
next() // pass control to the next handler
})
curl http://192.168.0.110:8111/configall
このように、res.send()
を書いてあげれば、Cannot POST
エラーは出なくなります。