杰网资源 Design By www.escxy.com

某个人问的问题:
我本来想获取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杂记:

<"htmlcode">
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") 

问题就这样完美的解决了,但是那个人连声谢谢都没有,真是世风日下。
原文:http://demon.tw/programming/vbs-http-302-redirect.html

标签:
重定向,URL

杰网资源 Design By www.escxy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
杰网资源 Design By www.escxy.com