检查网站是否可以联系 [英] Check if website is contactable
本文介绍了检查网站是否可以联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查一个特定的网站是否在线。网站的名称来自输入字段,并通过邮件发送。
I want to check if a specific website is online. The name of the website comes from an input field and is sending via post.
有一个用于ping主机的NPM模块,但这不足以帮助我。我需要一个使用参数检查URL的解决方案,如: hostname.com/category
There is an NPM module for ping hosts, but this do not help me so much. I need a solution for checking URL's with params, like: hostname.com/category
我将不胜感激建议。
推荐答案
只需进行HTTP请求。
Just make an HTTP request.
var http = require('http');
http.get('http://example.com/category', function (res) {
// If you get here, you have a response.
// If you want, you can check the status code here to verify that it's `200` or some other `2xx`.
}).on('error', function(e) {
// Here, an error occurred. Check `e` for the error.
});;
这篇关于检查网站是否可以联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文