var http = require('http');
var querystring = require('querystring');
var fs = require('fs');
var data = '{"uid":"502acbd07fc640768ac3621bfaa55be4","pageSize":10,"pageIndex":0}';
var moment = require('moment');
var shijian = moment().format('YYYYMMDD')
console.log(shijian);
var options = {
hostname: '016888.net',
port: 80, //端口号 https 默认端口 443,http 默认的端口号是 80
path: '/personProduct/getPersonProductByType.action',
method: 'POST',
headers: {'Connection': 'keep-alive','User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36',
'Content-Type': 'application/json;charset=UTF-8',
'Accept': 'application/json, text/javascript',
'Content-Length': 70}
};
var req=http.request(options,function(res){
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var resultObject = JSON.parse(responseString);
for(var i=0;i < resultObject.data.rows.length;i++){
var r=resultObject.data.rows[i];
for (var b = 0; b < r.pics.picList.length; b++) {
console.log(r.pics.picList[b]+'保存完成');
fs.writeFile('./imgs/'+shijian+'_'+r.code+'_'+b+'.jpg',r.pics.picList[b],'binary', function (err) {
if (err) throw err;
});
}
}
});
req.on('error', function(e) {
console.log('-----error-------',e);
});
});
req.write(data);
req.end();
1
8qwe24657913 2018-02-09 20:08:20 +08:00
哪里空了,这不是往.jpg 文件里写了 104 字节的图片 URL 吗(笑)
|
2
luoo369 OP 刚学 nodejs,下载的图片 打开时空的。。
@8qwe24657913 |
3
azh7138m 2018-02-09 20:40:44 +08:00 via Android
这个 writeFile 非常灵性了
|