Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I check to see if a URL exists without pulling it down?(如何检查URL是否存在而没有将其拉下?)

I use the following code, but it downloads the whole file.(我使用以下代码,但是它将下载整个文件。) I just need to check that it exists.(我只需要检查它是否存在。) app.get('/api/v1/urlCheck/', function (req,res) { var url=req.query['url']; var request = require('request'); request.get(url, {timeout: 30000, json:false}, function (error, result) { res.send(result.body); }); }); Appreciate any help!(感谢任何帮助!)   ask by metalaureate translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
208 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:(尝试这个:)

var http = require('http'), options = {method: 'HEAD', host: 'stackoverflow.com', port: 80, path: '/'}, req = http.request(options, function(r) { console.log(JSON.stringify(r.headers)); }); req.end();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...