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();
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();
本文介绍了一个使用Node.js发起HTTP POST请求的例子。该示例展示了如何配置请求选项、处理响应状态码及数据,并且能够捕获错误。对于理解HTTP交互过程和错误处理非常有用。

被折叠的 条评论
为什么被折叠?



