1、Msxml2.ServerXMLHTTP可以任意提交cookie,但是post模拟登陆后,获取cookie一般会找不到set-cookie,多数因网站跳转了,用chrome F12看,302或者303了,跳转之前返回的response是可以看到set-cookie的。Msxml2.ServerXMLHTTP可能太高级了,对303等跳转直接处理了,我们无法敢于,也就是说Msxml2.ServerXMLHTTP获取的cookie是跳转后的页面的http头,当然没有了。
2、解决:用winhttp。其中WinHttp.Option(6) = False,就是不自动跳转。这样返回的.getResponseHeader("Set-Cookie")就有cookie了。
response.Write(WinHttpPost("http://192.168.0.3/login/","username=bianchao&password=123456"))
Function WinHttpPost(PostUrl,PostData)
Dim WinHttp
Set WinHttp = server.createobject("WinHttp.WinHttpRequest.5.1")
WinHttp.Open "POST", PostUrl, false
WinHttp.Option(4) = 13056
WinHttp.Option(6) = False
WinHttp.setTimeouts 5000,5000,5000,5000
WinHttp.setRequestHeader "Cookie", "string"
WinHttp.setRequestHeader "Connection", "keep-alive"
WinHttp.setRequestHeader "Content-Length",Len(PostData)
WinHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttp.setRequestHeader "Referer", "http://192.168.0.3/login/"
WinHttp.Send PostData
WinHttpPost=WinHttp.getResponseHeader("Set-Cookie")
Set WinHttp = nothing
End Function