将 HTML/Express.js 设置从 POST 更改为 PUT?
Changing HTML/Express.js setup from POST to PUT?
我有一个运行良好的函数,但我意识到我正在使用一个 POST 函数,而它可能适合使用 PUT。
我把app.post('/word', docType, function (req. res) {
换成了app.put
然后在html我切换:
<form action="/mediaDev/word" method="post" enctype="multipart/form-data">
至:method="put"
进行此更改后,我最终得到 502 Bad Gateway
。
POST 和 PUT 之间是否存在我在这里遗漏的关键区别?
您是否检查过实际提出的请求?应该是GET吧。
有关详细信息,请参阅 "Using PUT method in HTML form"...
According to the HTML standard, you can not. The only valid values for the method attribute are get and post, corresponding to the GET and POST HTTP methods. <form method="put">
is invalid HTML and will be treated like <form>
, i.e. send a GET request.
编辑:再三考虑我不确定为什么这意味着您会得到一个 502 Bad Gateway,但是我会留下这个答案,因为我相信它仍然有用。
我有一个运行良好的函数,但我意识到我正在使用一个 POST 函数,而它可能适合使用 PUT。
我把app.post('/word', docType, function (req. res) {
换成了app.put
然后在html我切换:
<form action="/mediaDev/word" method="post" enctype="multipart/form-data">
至:method="put"
进行此更改后,我最终得到 502 Bad Gateway
。
POST 和 PUT 之间是否存在我在这里遗漏的关键区别?
您是否检查过实际提出的请求?应该是GET吧。
有关详细信息,请参阅 "Using PUT method in HTML form"...
According to the HTML standard, you can not. The only valid values for the method attribute are get and post, corresponding to the GET and POST HTTP methods.
<form method="put">
is invalid HTML and will be treated like<form>
, i.e. send a GET request.
编辑:再三考虑我不确定为什么这意味着您会得到一个 502 Bad Gateway,但是我会留下这个答案,因为我相信它仍然有用。