|
我想做一个飞信自动发短信的程序,我的想法是先用POST方法登陆系统(网址为:http://f.10086.cn/im/login/inputpasssubmit1.action),之后再用POST方法发送短息。之前论坛里也有飞信方面的接口(见http://club.excelhome.net/forum.php?mod=viewthread&tid=744110),但是这个接口已经用不了了,因为登陆的时候多了一个验证码,所以不能用原来的方法即输入用户名,密码,然后POST自动登陆,再POST发信息。我的问题是如果手动输入用户名、密码、验证码,然后再用XMLHTTP对象 POST登陆系该如何做呢?我查了很多地方都没有这方面的资料。我也尝试了很多方法比如:
Sub TT() ‘参考了http://club.excelhome.net/thread-899268-1-1.html
Dim CookieHeaders, Cookie, i&, HTML$, CODE$, st$
Dim tmp() As String, p As Long, arr() As String, xmlhttp As Object, t As Single
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
With xmlhttp
.Option(6) = 0
.Open "GET", " http://f.10086.cn/im/login/inputpass.action", False
.setRequestHeader "Connection", "keep-alive"
.SEND
Cookie = .getallResponseHeaders()
' With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'DataObject对象,数据放入剪贴板,记事本观察数据
' .SetText Cookie
' .PutInClipboard
' End With
CookieHeaders = Filter(Split(.getallResponseHeaders(), Chr(10)), "Set-Cookie") '获取Cookie
For i = 0 To UBound(CookieHeaders)
CookieHeaders(i) = Split(Split(CookieHeaders(i), ": ")(1), ";")(0)
Next
Cookie = ""
For i = 0 To i - 1
Cookie = Cookie & CookieHeaders(i) & ";"
Next
Cookie = Left(Cookie, Len(Cookie) - 1)
HTML = .responsetext
’Debug.Print HTML
st = getPitureString(HTML)‘获取源码里的验证码图片的地址
Call DownloadImage(st, "C:\verifycode.jpeg")’把图片下载到本地
UserForm1.Show‘显示下载到本地的验证码图片,并手动输入验证码
CODE = UserForm1.TextBox1.Text’获取验证码
End With
With xmlhttp
.Open "POST", "http://f.10086.cn/im/login/inputpass.action", False
.Option(6) = 1
.setRequestHeader "Referer", "http://f.10086.cn"
.setRequestHeader "Cookie", Cookie
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Content-Length", Len("m=12312321&pass=212312113&loginstatus=4&captchaCode=" & CODE)
.setRequestHeader "Connection", "Keep-Alive"
.SEND "m=12312321&pass=212312113&loginstatus=4&captchaCode=" & CODE
HTML = .responsetext
Debug.Print HTML
End With
Set xmlhttp = Nothing
End Sub
最后发现还是登陆不了,说验证码错误。我是先显示登陆页获取验证码及COOKIE,然后用该COOKIE及获取的验证码POST登陆。不知为什么不行,求高手指教?
|
|