level 1
najlaya
楼主
const http = require('http');
const application = { 'msg':'你好!'};
const options = {
hostname:'localhost',
port:8080,
path:'/test',
method:'post',
headers:{
'Content-Type': 'application/json',
},
}
const req = http.request(options,(res)=>{
console.log(`状态码: ${res.statusCode}`);
console.log(`响应头: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(JSON.parse(chunk))
});
});
req.on('error',(e)=>{
console.error(`请求遇到问题:${e.message}`);
})
req.write(JSON.stringify(application));
req.end();
官网荡下来的代码,node运行后报res is not defined;
啥情况?有没有大神帮忙看看~
2021年01月20日 07点01分
1
const application = { 'msg':'你好!'};
const options = {
hostname:'localhost',
port:8080,
path:'/test',
method:'post',
headers:{
'Content-Type': 'application/json',
},
}
const req = http.request(options,(res)=>{
console.log(`状态码: ${res.statusCode}`);
console.log(`响应头: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(JSON.parse(chunk))
});
});
req.on('error',(e)=>{
console.error(`请求遇到问题:${e.message}`);
})
req.write(JSON.stringify(application));
req.end();
官网荡下来的代码,node运行后报res is not defined;
啥情况?有没有大神帮忙看看~