您的位置:首页 > 理论基础 > 计算机网络

nodejs的http.request如何发送带参数的post请求?

2015-06-29 14:00 701 查看
var opt = {
     host:'localhost',
     port:'8888',
     method:'POST',
     path:'/getTicket',
     headers:{

     }
}

var body = '';
var req = http.request(opt, function(res) {
    console.log("Got response: " + res.statusCode);
    res.on('data',function(d){
        body += d;
    }).on('end', function(){
        console.log(res.headers)
        console.log(body)
    });
}).on('error', function(e) {
    console.log("Got error: " + e.message);
})
req.end();
req.end()
之前加上:
data = {user:"hello",password:"world"};
req.write(require('querystring').stringify(data));
http://nodejs.org/api/http.html#http_request_write_chunk_encoding
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: