通过http模块获取一个数据值,如下:
http.request(options,function(res){
console.log('Status:'+res.statusCode)
//console.log('Headers:'+JSON.stringify(res.headers))
console.log(res.body)
res.on('data',function(chunk){
...
})
res.on('end',function(){
console.log('发送完毕')
})
})
options配置:
var options = {
host:'www.123.com',
port:80,
path:'/course/AjaxCourseMembers?ids='+ids,
method:'GET',
headers:{
'Accept':'*/*',
'Accept-Encoding':'gzip, deflate, sdch',
.....
}
}
输出的res.statusCode为200但是在res却得不到json数据,而通过jQuery是可以获取到正确数据的,请问是哪里的问题?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
怎么不用
request模块