这个模块是'request https://github.com/mikeal/request
我想我正在遵循每一步,但我错过了一个论点..
var request = require('request');
request.post({
url: 'http://localhost/test2.php',
body: "mes=heydude"
}, function(error, response, body){
console.log(body);
});
在另一端我有
echo $_POST['mes'];
我知道php没有错...
6 回答
安装请求模块,使用
npm install request
在代码中:
EDIT: 你应该看看Needle . 它为您完成此操作并支持多部分数据等等 .
我发现我错过了一个 Headers
将
request
用于http POST时,您可以通过以下方式添加参数:我不得不发布没有形式的键值对,我可以像下面这样轻松地做到:
好读:http://blog.modulus.io/node.js-tutorial-how-to-use-request-module
如果您要发布json正文,请不要使用
form
参数 . 使用form
将使数组成为field[0].attribute
,field[1].attribute
等 . 而是像这样使用body
.