当前位置: 移动技术网 > IT编程>脚本编程>VBScript > VBS获取重定向的URL的代码

VBS获取重定向的URL的代码

2017年12月08日  | 移动技术网IT编程  | 我要评论
某个人问的问题: 我本来想获取aaa.com页面的内容,可是aaa.com跳转到bbb.com了。我想获取bbb.com 这个网址。 访问了一下他所谓的aaa.co

某个人问的问题:
我本来想获取aaa.com页面的内容,可是aaa.com跳转到bbb.com了。我想获取bbb.com 这个网址。
访问了一下他所谓的aaa.com,发现是http 302重定向

http/1.1 302 moved temporarily
server: nginx/0.8.53
date: fri, 08 apr 2011 15:49:25 gmt
content-type: text/html;charset=utf-8
transfer-encoding: chunked
connection: keep-alive
x-powered-by: php/5.2.15
location: http://tuan.sohu.com/beijing/life/

为了测试方便,我写了一个302.php,重定向到小顾de杂记:

<?php 
header('location: http://ihipop.info/'); 
?> 

先用xmlhttp试试:

dim http 
set http = createobject("msxml2.serverxmlhttp") 
http.open "get", "http://demon.tw/test/302.php", false 
http.send 
wscript.echo http.responsetext 

xmlhttp组件在处理包含location头的302消息时太智能,直接给跳转到location指定的页面了。
xmlhttp不行,我们还有winhttp.winhttprequest.5.1,该组件的option属性的第六个索引enableredirects就是指示是否自动跳转:

dim winhttp 
set winhttp = createobject("winhttp.winhttprequest.5.1") 
winhttp.open "get", "http://demon.tw/test/302.php", false 
winhttp.option(6) = false 
winhttp.send 
wscript.echo winhttp.getresponseheader("location") 

问题就这样完美的解决了,但是那个人连声谢谢都没有,真是世风日下。
原文:

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网