验证中...
Languages: JavaScript
Categories: 常用工具包
Latest update 2019-08-22 15:45
post.js
Raw Copy
var http=require('http');
var qs=require('querystring');
var post_data={a:123,time:new Date().getTime()};//这是需要提交的数据
var content=qs.stringify(post_data);
var options = {
host: 'www.baidu.com',
port: 80,
path: '/',
method: 'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded',
'Content-Length':content.length
}
};
console.log("post options:\n",options);
console.log("content:",content);
console.log("\n");
var req = http.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
var _data='';
res.on('data', function(chunk){
_data += chunk;
});
res.on('end', function(){
console.log("\n--->>\nresult:",_data)
});
});
req.write(content);
req.end();

Comment list( 0 )

You need to Sign in for post a comment

Help Search