标题: [网络连接] 批处理如何访问网址并获得内容来判段是否有500,404等错误? [打印本页]
作者: dicksamfeng 时间: 2015-10-23 08:59 标题: 批处理如何访问网址并获得内容来判段是否有500,404等错误?
现在我要写一个网页检测bat 名字叫webValidation.bat
逻辑是这样的,我要检测一个固定网页www.test.com,如果网页返回500或者404就调用之前已经写好的run.bat,
请问webValidation.bat里的逻辑该怎么实现?
作者: pcl_test 时间: 2015-10-23 10:51
- //&cls&cscript -nologo -e:jscript "%~f0" "http://www.bathome.net"&pause&exit
- var url = WScript.arguments(0);
- http = new ActiveXObject('Msxml2.XMLHTTP');
- try {
- http.open("GET", url, false);
- http.send(null);
- var st = http.status;
- WSH.echo(st);
- if (st =='500'||st =='404')
- new ActiveXObject('Wscript.Shell').run('D:\\run.bat');
- } catch (e) {
- WSH.echo(e);
- }
复制代码
作者: 依山居 时间: 2015-10-23 16:21
curl -I www.baidu.com
第一行会返回状态码。
作者: 依山居 时间: 2015-10-23 17:02
国外友人的问题
http://superuser.com/questions/9 ... -timing-the-request
http://superuser.com/questions/2 ... ut-http-status-code
作者: 依山居 时间: 2015-10-23 17:03
Ping any URL or web site with our free command-line utility, http-ping
命令行工具, http-ping
是个http命令行客户端。
http://www.coretechnologies.com/products/http-ping/
作者: 依山居 时间: 2015-10-23 17:28
c:\>curl -sL -w "%{http_code}" "www.baidu.com" -o /dev/null
200
作者: 依山居 时间: 2015-10-23 17:37
我是状态码,还好不是返回250
c:\>curl -sL -w "我是状态码:%{http_code}" www.baidu.com -o /dev/null
我是状态码:200
作者: 依山居 时间: 2015-10-23 17:38
http://beerpla.net/2010/06/10/ho ... e-code-in-cli-curl/
-w 参数的变量
url_effective
http_code
http_connect
time_total
time_namelookup
time_connect
time_pretransfer
time_redirect
time_starttransfer
size_download
size_upload
size_header
size_request
speed_download
speed_upload
content_type
num_connects
num_redirects
ftp_entry_path
作者: ahbzlong 时间: 2020-9-26 09:01
回复 2# pcl_test
返回200的时候怎么执行另一个程序?
作者: Batcher 时间: 2020-9-27 11:46
回复 9# ahbzlong
参考:
http://bbs.bathome.net/thread-52172-1-1.html#pid217940
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |