|
目标:使用winhttp5.1编程抓取https://frontier.nanch.95306.cn/gateway/hydzsw/Dzsw/security/jcaptcha.jpg验证码信息
测试情况:使用xmlhttp可以很方便的获得回应,但winhttp5.1获取不到,由于需要后期想使用cookie,所以要使用winhttp5.1。
Winhttp5.1代码如下,请高手帮忙指点下:
Dim picAry() As Byte
Set Xml = CreateObject("WinHttp.WinHttpRequest.5.1")
'设置连接或发送超时参数
WinHttp.setTimeOuts 20000, 20000, 20000, 60000 '0表示无限制
Xml.Open "GET", "https://frontier.nanch.95306.cn/gateway/hydzsw/Dzsw/security/jcaptcha.jpg", True
Xml.setRequestHeader "Cache-Control", "no-cache"
Xml.setRequestHeader "If-Modified-Since", "0"
Xml.Send
picAry = Xml.responseBody
'保存验证码图片文件
Call WriteBinary(ThisWorkbook.Path & "\verycode.gif", picAry)
以下是使用xmlhttp成功获取图片的代码:
Xml.Open "GET", "https://frontier.nanch.12306.cn/gateway/hydzsw/Dzsw/security/jcaptcha.jpg", True
Xml.setRequestHeader "Cache-Control", "no-cache"
Xml.setRequestHeader "If-Modified-Since", "0"
Xml.Send
Do Until Xml.ReadyState = 4
DoEvents
Loop
picAry = Xml.responseBody
'保存验证码图片文件
Call WriteBinary(ThisWorkbook.Path & "\verycode.gif", picAry)
|
|