|
公司内网,我用xmlhttp自动登录,并找到URL,连续下载两个文件,第一个文件下载成功,第二个文件就下载不成功。在浏览器上,直接输入登录的URL,再连续输入文件的URL,又都能下载成功,什么原因呢?
Set dwjh = CreateObject("msxml2.xmlhttp.3.0")
Set dwjs = CreateObject("adodb.stream")
dwjh.Open "post", 登录URL, False
dwjh.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
dwjh.Send
Do
DoEvents
If dwjh.ReadyState = 4 Then Exit Do
Loop
dwjh.Open "post", URL, False
dwjh.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
dwjh.Send
Do
DoEvents
If dwjh.ReadyState = 4 Then Exit Do
Loop
dwjs.Type = 1
dwjs.Open
dwjs.Write dwjh.responseBody
dwjs.savetofile Application.CurrentProject.Path & "\123456.xlsx", 2
dwjs.Close
dwjh.Open "post", URL2, False
dwjh.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
dwjh.Send
Do
DoEvents
If dwjh.ReadyState = 4 Then Exit Do
Loop
dwjs.Type = 1
dwjs.Open
dwjs.Write dwjh.responseBody
'Debug.Print dwjh.responseBody
dwjs.savetofile Application.CurrentProject.Path & "654321.xlsx", 2
dwjs.Close |
|