大神求救啊!原生http模块报错res未定义……
node吧
全部回复
仅看楼主
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
level 1
najlaya 楼主
没人吗?~~~哭了啊。
2021年01月20日 07点01分 2
level 1
najlaya 楼主
。。。我**了。。。后端没传参~
打扰了!对不起!!!
2021年01月20日 07点01分 3
level 10
res你是形参调用吧,你要传参啊
2021年06月19日 22点06分 4
1