首页 > 解决方案 > NodeJS POST method not working with request module

问题描述

I included require module and trying to post data to a php file.

Code: request.post('http://localhost/actions.php?setonline',{user});

There is no error and no not working. Do I something wrong?

标签: node.jspostrequest

解决方案


request.post('http://localhost/actions.php?setonline',{user})正在返回 astream并且您没有处理它的任何事件,这就是您看不到任何输出的原因。

在任何情况下,您可能想要的是使用回调,并获得缓冲的响应。

request.post('http://localhost/actions.php?setonline',{user}, (err, response, body) => {
   console.log(err, response, body);
});

推荐阅读