express中如何读取远程的图片并显示出来?
发布于 8 年前 作者 seostar 6837 次浏览 来自 问答

用的是request来发送请求,图片显示不出来 router.get(’/identify’,function(req,res,next){ var opts={ url:‘https://pin.aliyun.com/get_img?sessionid=7e9c5e38c107ad7d4cb1f28909af4076&identity=passport.alipay.com&type=bak_150_40&dt=1449560761782&t=1449560760917’ } request.get(opts, function (err, response, body) { var type = response.headers[“content-type”]; res.writeHead(200,{“Content-Type”:type}); res.write(body); res.end(); }) })

3 回复

试下 opts 里面加个 encoding: null

pipe(res)就行了

//set your header here...
request.get(opt).pipe(res);
回到顶部