简单的 POST 请求像 GET 请求一样工作并超时
Simple POST request working like a GET request and timing out
我创建了一个简单的 POST 请求表单来提交电子邮件,但每次我 运行 它就像一个失败的 GET 请求一样。
我尝试在邮递员中对其进行测试,但收到一条消息说 "Could not get any response"。该表格非常基础,但我在网上找不到任何描述我的问题和有效解决方案的内容。
我已经在我的本地服务器、Heroku 服务器和 Godaddy 共享主机服务器上试过了,它们的行为都一样。
我试过添加不必要的斜杠,完全更改 URl,并删除除 console.log 以外的所有内容。
app.post('/sendEmail', (req, res) => {
console.log('post test');
});
<form method="POST" action="/sendEmail">
<h1>Contact Me</h1>
<hr id="contact-page-hr">
<h4>I am here to serve YOU. Please send your questions my way.</h4>
<h6 id="contact-name-label"><span><input type="text" name="name" placeholder=" Name" value="" id="contact-name-input" required></span></h6>
<h6 id="contact-email-label"><span><input type="email" name="email" placeholder=" Email" id="contact-email-input" required></span></h6>
<h6 id="contact-message-label"></h6>
<textarea name="message" id="contact-message-input" placeholder=" What's on your mind?"></textarea>
<h6 class="sub-heading">(I usually reply within 48 hours)</h6>
<button type="submit" class="send-button" id="contact-page-send">Send</button>
</form>
我希望页面保持不变,但它却显示:
“safari 无法打开页面 'localhost:5000/sendEmail/' 因为服务器意外断开连接...
它本质上就像一个 GET 请求
您的请求处理程序未发送任何响应。因此,浏览器或服务器最终会超时等待响应的连接。
HTTP 请求需要某种响应。您需要 res.send()
或 res.redirect()
来自请求处理程序的内容。
仅当您通过 Ajax 调用发送 POST 请求时,该页面才会保持不变,但如果您进行非 Javascript 表单提交则不会。浏览器表单提交需要一个新的 HTML 页面或类似 302 重定向的内容作为其响应,客户端和服务器都在等待您的代码发送该页面,直到其中一个最终超时并错误地关闭连接。
我创建了一个简单的 POST 请求表单来提交电子邮件,但每次我 运行 它就像一个失败的 GET 请求一样。
我尝试在邮递员中对其进行测试,但收到一条消息说 "Could not get any response"。该表格非常基础,但我在网上找不到任何描述我的问题和有效解决方案的内容。
我已经在我的本地服务器、Heroku 服务器和 Godaddy 共享主机服务器上试过了,它们的行为都一样。
我试过添加不必要的斜杠,完全更改 URl,并删除除 console.log 以外的所有内容。
app.post('/sendEmail', (req, res) => {
console.log('post test');
});
<form method="POST" action="/sendEmail">
<h1>Contact Me</h1>
<hr id="contact-page-hr">
<h4>I am here to serve YOU. Please send your questions my way.</h4>
<h6 id="contact-name-label"><span><input type="text" name="name" placeholder=" Name" value="" id="contact-name-input" required></span></h6>
<h6 id="contact-email-label"><span><input type="email" name="email" placeholder=" Email" id="contact-email-input" required></span></h6>
<h6 id="contact-message-label"></h6>
<textarea name="message" id="contact-message-input" placeholder=" What's on your mind?"></textarea>
<h6 class="sub-heading">(I usually reply within 48 hours)</h6>
<button type="submit" class="send-button" id="contact-page-send">Send</button>
</form>
我希望页面保持不变,但它却显示:
“safari 无法打开页面 'localhost:5000/sendEmail/' 因为服务器意外断开连接...
它本质上就像一个 GET 请求
您的请求处理程序未发送任何响应。因此,浏览器或服务器最终会超时等待响应的连接。
HTTP 请求需要某种响应。您需要 res.send()
或 res.redirect()
来自请求处理程序的内容。
仅当您通过 Ajax 调用发送 POST 请求时,该页面才会保持不变,但如果您进行非 Javascript 表单提交则不会。浏览器表单提交需要一个新的 HTML 页面或类似 302 重定向的内容作为其响应,客户端和服务器都在等待您的代码发送该页面,直到其中一个最终超时并错误地关闭连接。