VB用Post方式登录学校网站能成功,但记笔记总是失败,急求大神帮忙看下!
vb用post方式登录学校网站,刚开始用的webbrowser模拟点击,可以登录,记笔记,但由于加载内容过多总假死,用了DoEvents也没用。只能换Post方式,因为要获取Cookie登录用的是Inet控件,
学校的登录网址如下:
http://www.hust-snde.com/center/left_hydl.jsp?url=www.hust-snde.com:80/sso/login_centerLogin.action
登录部分代码如下:
Dim myurl As String, send_data As String, my_head As String
myurl = "http://cas.hust-snde.com/whatyVerify"
send_data = "username=W201700958&password=" & MD5("321324198705175425") & "&service=http%3A%2F%2Fsns.hust-snde.com%2Flearning%2Fsso%2Flogin_webTrnLogin.action%3FssoUser.loginId%3DW201700958%26siteCode%3Dcode62"
my_head = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
Inet1.Execute myurl, "POST", send_data, my_head
While Inet1.StillExecuting
DoEvents
Wend
Dim Buff() As Byte
Buff = Inet1.GetChunk(0, icByteArray)
If InStr(1, Utf8ToUnicode(Buff), "主机没有反应,连接尝试失败") Then
MsgBox "登录失败,对方网站没有响应!"
Else
’WebBrowser1.Navigate "http://sns.hust-snde.com/learning/entity/student/student_studentCourseList.action"
End If
以下部分是记笔记的代码:
myurl = "http://sns.hust-snde.com/learning/studyLog/studyLog_saveStudyLog.action"
send_data ="studyLog.isPub=0&studyLog.studyNote=%E7%AB%8B%E6%B3%95%E6%9D%83&studyLog.tagId=ff8080815bafb5c4015bc6b91d282781_03005760&studyLog.coursewareId=&studyLog.coursewareName="
my_head = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
my_head = my_head & "Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" & vbCrLf
my_head = my_head & "Referer: http://sns.hust-snde.com/learning/studyLog/studyLog_myStudylog.action" & vbCrLf
my_head = my_head & "Accept-Language: zh-CN" & vbCrLf
my_head = my_head & "Accept-Encoding: gzip, deflate" & vbCrLf
my_head = my_head & "Connection: Keep-Alive" & vbCrLf
Inet1.Execute myurl, "POST", send_data, my_head
While Inet1.StillExecuting
DoEvents
Wend
登录能成功,包括之前用webbrowser识别验证码然后再登录的,只是发帖一直没效果,用Winhttp带Cookie也一样,只有点击了webbrowser1窗口中“开始学习”按钮并等课件在webbrowser2中加载完再用代码Post方式记笔记的话就能成功(然后通过抓包工具抓取数据包再post"开始学习"按钮对应跳转的网页的话也没用)。
之前没怎么接触过Webbrowser、Inet控件、xmlhttp、Winhttp那种,希望大神帮忙,万分感谢!