欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

VBS获取重定向的URL的代码

程序员文章站 2022-07-04 20:32:30
某个人问的问题: 我本来想获取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") 

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