简体   繁体   English

node.js接收使用HTTP通过表单提交的POST数据

[英]node.js receiving POST data submitted through form using HTTP

I'm using a node.js server and need to post data over an http* s * protocol. 我使用的是node.js服务器,需要通过http * s *协议发布数据。

POST is listed as a http protocol, so I'm wondering if I'm on the wrong track. POST被列为http协议,因此我想知道自己是否走错了路。

Anyway, here is the top of my code that handles the POST. 无论如何,这是我处理POST的代码的顶部 I've not included the on('end') function for berevity, but it is there. 我没有包含berevity的on('end')函数,但是它在那里。

exports.login = function(req, res){
if(req.method == 'POST'){
    var datastring = '';
    req.on('data', function(data){
        datastring += data;
        console.log("getting data");
        if(datastring.length > 1e6){
            req.connection.destroy();
        }
    });

Through console logs I can determine that the request is being made, and that the request is recognised as POST, but that req.on('data')'s function is never called. 通过控制台日志,我可以确定正在发出请求,并且该请求被识别为POST,但是从未调用过req.on('data')函数。

I looked into a CONNECT protocol, but this isn't supported by browser forms - please advise how to send data through CONNECT if you don't think I can send POST data over HTTPS 我调查了CONNECT协议,但是浏览器表单不支持此协议-如果您认为我无法通过HTTPS发送POST数据,请告知如何通过CONNECT发送数据

Thanks for your help 谢谢你的帮助

EDIT: here is form that sends request: 编辑:这是发送请求的表格:

<form name="loginForm" action="login" method="POST" onsubmit="return checkForm()" class="separate-sections">

and here is node.js code that grabs post 这是获取帖子的node.js代码

var app= express();
...
app.post('/login', route_login.login);

To make a long story short, does POST work over HTTPS? 简而言之,POST是否可以通过HTTPS进行工作? It doesn't seem to be working here. 它似乎在这里不起作用。

Found out someone on my team had added the express bodyparser, so naturally posts no longer work in the way I had before. 发现我的团队中有人添加了快速的bodyparser,因此自然而然地发布帖子不再像以前那样有效。 The change just happened to coincide with when we switched to https which made it look as if this was the issue, when it was not. 当我们切换到https时,更改恰好与之吻合,这使问题看起来像是问题,而并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM