|

楼主 |
发表于 2014-10-23 23:16
|
显示全部楼层
本帖最后由 wcymiss 于 2014-10-24 07:00 编辑
blanksoul12 发表于 2014-10-23 22:56 
我直接COPY妳那個程序出來的
晚上正在找重定向的例子进行测试的时候,发现了我电脑winhttp控件居然有个bug。
我的winhttp对于301重定向的网页运行正常,对于302重定向的网页,不管option(6)怎么设置,都不会重定向到新的网页。汗!!
34楼的这个网页,正好是一个302重定向的网页,所以我的winhttp没有进行重定向,返回的信息是原网页的。我还以为option(6)默认是false,测试了才发现默认是true
正确的代码应该还要加一句“.option(6)=false- Sub Main()
- Dim strText As String
- Dim strCookie As String
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Option(6) = False ' 禁止重定向,以获取原网页信息
- .Open "GET", "http://www.gzgczj.com:8080/costRegulatory/user.do?method=changeIndex&fareaId=1", False
- .Send
- strText = .getAllResponseHeaders '获取所有的回应头信息
- Debug.Print strText
- strCookie = Split(Split(strText, "JSESSIONID=")(1), ";")(0) '取出Cookie值
-
- .Open "GET", "http://www.gzgczj.com:8080/costRegulatory/project.do?method=showProjectList&isVisitor=1&f_id=11011&t1413902083242", False
- .setRequestHeader "Referer", "http://www.gzgczj.com:8080/costRegulatory/user.do?method=changeIndex&fareaId=1"
- .setRequestHeader "Cookie", strCookie '模拟Cookie
- .Send
- strText = .responsetext
- Debug.Print strText
-
- End With
- End Sub
复制代码 |
|