プログラミング

express.jsで”Cannot POST”(Cannot GET)となってしまう以外な原因

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

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です