|
wcymiss 发表于 2014-12-23 12:19
这个应该不难啊。准确发送__VIEWSTATE和__EVENTVALIDATION应该就可以啊(每次请求都要发送从上一次的resp ...
谢谢 吴姐百忙中帮忙解答,请帮忙指正。
转码代码如下
Public Function UTF8ToGB2312(ByVal varIn As Variant) As String
Dim bytesData() As Byte
Dim adoStream As Object
bytesData = varIn
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Charset = "utf-8"
adoStream.Type = 1 'adTypeBinary
adoStream.Open
adoStream.Write bytesData
adoStream.Position = 0
adoStream.Type = 2 'adTypeText
UTF8ToGB2312 = adoStream.ReadText()
adoStream.Close
End Function
思路为通过vba发送用户登陆信息,获取用户Set-Cookie (不知Cookie 存活时间,取新鲜的觉的靠谱)因为登陆后需要发送 用户Set-Cookie
测试代码
Dim strText As String
Dim strCookie As String
Dim strDlistUser As String
Dim strDLname As String
Dim strtxtPassword As String
strDlistUser = "**"
strDLname = "**"
strtxtPassword = "***"
With CreateObject("WinHttp.WinHttpRequest.5.1")
'第一次GET,获取VIEWSTATE和EVENTVALIDATION
.Open "GET", "主页/login.aspx", False'初始用户信息
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send
strText = .responsetext
VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0)))
EVENTVALIDATION = encodeURI(CStr(Split(Split(strText, "__EVENTVALIDATION"" value=""")(1), """ />")(0)))
'第二次POST,获取指用户的VIEWSTATE和EVENTVALIDATION
.Open "POST", "主页/login.aspx, False"
.setRequestHeader "Content-Type", "主页/login.aspx"
.Send "__LASTFOCUS=&__EVENTTARGET=btnLogin&__EVENTARGUMENT=&__VIEWSTATE=" & VIEWSTATE _
& "&DlistUser=" & strDlistUser _
& "&DLname= " & strDLname _
& "&txtPassword=" & strtxtPassword _
& "&__EVENTVALIDATION=" & EVENTVALIDATION
strText = .responsetext
VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0)))
EVENTVALIDATION = encodeURI(CStr(Split(Split(strText, "__EVENTVALIDATION"" value=""")(1), """ />")(0)))
strText = .responsetext
Debug.Print strText
End With
|
|