使用InternetExplorer.Applicaion获取响应标头? [英] Get Response Header Using InternetExplorer.Applicaion?

查看:108
本文介绍了使用InternetExplorer.Applicaion获取响应标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我,或者至少指向我正确的方向.

could someone help me or at the very least point me in the right direction.

我正在尝试在VBA中编写一个自动化脚本,该脚本将登录到网站并单击该网站上的一些按钮和复选框,然后触发下载.

I am attempting to write an automation script in VBA that will log into a web site and hit some buttons and checkboxes on that site which will then trigger a download.

该网页正在使用ASP.net.

The webpage is using ASP.net.

我可以通过使用InternetExplorer.Applicaion对象完全实现我想要的功能,但是问题是我正在使用API​​和SendKeys将文件保存到SaveAs对话框窗口中,它可以工作,但是非常粗糙,很容易失败,并且我真的希望它能够独立运行而没有任何问题.

I can achieve exactly what i want by using the InternetExplorer.Applicaion object but the problem is with saving the file as i am using APIs and SendKeys to the SaveAs dialog window, it works but is very crude and can easily fail and i really want this to be able to run on its own without any issues.

理想情况下,我希望能够使用HTTP请求/响应方法,但是由于站点身份验证,我已经尝试了数小时而没有成功,并且我也认为它具有一些针对脚本的保护措施,因为cookie文件具有HttpOnly标志集.

Ideally i would love to be able to use a HTTP request / response approach but i have been trying for hours without any success due to the sites authentication and i also think it has some protection against scripts as the cookie file has the HttpOnly flag set.

我要下载的文件是text/csv,可以通过http响应标头访问输出的数据,我可以通过Fiddler看到该标头.

The file i want to download is text/csv and the outputted data can be accessed via the http response header which i can see via Fiddler.

是否有任何方法可以从InternetExplorer.Applicaion对象获取HTTP响应标头,我一直在查看MS文档,但看不到任何明显的方法?

Is there any way to get the HTTP response header from the InternetExplorer.Applicaion object, i have been looking at the MS documentation and I do not see any obvious way to get to this?

这是我目前正在使用的代码:

Here is the code i am using at the moment:

Private Function GetFile() As Scripting.File

On Error Resume Next

Dim objFso As Scripting.FileSystemObject: Set objFso = New Scripting.FileSystemObject

Dim strFileName As String: strFileName = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now()) & ".csv"
Dim strFolder As String: strFolder = objFso.GetAbsolutePathName(Environ("TEMP")) & "\"

Dim strSaveAsFullPath As String: strSaveAsFullPath = strFolder & strFileName

Dim objIE As InternetExplorer: Set objIE = New InternetExplorer

With objIE

    .Visible = True

    .Navigate2 "WEB URL 1"

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
        DoEvents
    Loop

    .Document.getElementById("ctl02_txtUserId").value = "USER"
    .Document.getElementById("ctl02_txtPassword").value = "PASS"
    .Document.getElementById("ctl02_btnLogon").Click

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
        DoEvents
    Loop

    .Navigate2 "WEB URL 2"

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
        DoEvents
    Loop

    .Document.getElementById("ddlTables").selectedIndex = 8
    .Document.forms(0).submit

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
    Loop

    .Document.getElementById("gvFields_lnkbtnSelectAll").Click

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
        DoEvents
    Loop

    .Document.getElementById("btnRetrieveData").Click

    Do Until Not .Busy
        Application.Wait Now + TimeValue("00:00:01")
        DoEvents
    Loop

    .Document.getElementById("btnRetrieveData").Focus

'''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''' '这是我正在使用SENDKEYS下载文件的地方:( 请提供更好的解决方案??? '''''''''''''''''''''''''''''''''''''''''''''''' ''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'THIS IS WHERE I AM DOWNLOADING THE FILE USING SENDKEYS :( 'I NEED A BETTER SOLUTION PLEASE ??? ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Application.Wait Now + TimeValue("00:00:01")
    DoEvents

    Application.SendKeys "{TAB}", True
    Application.SendKeys "{TAB}", True
    Application.SendKeys "{DOWN}", True
    Application.SendKeys "{DOWN}", True

    Application.SendKeys "a", True

    Application.Wait Now + TimeValue("00:00:01")
    DoEvents

    Application.SendKeys strSaveAsFullPath, True

    Application.SendKeys "{TAB}", True
    Application.SendKeys "{TAB}", True
    Application.SendKeys "{TAB}", True
            Application.Wait Now + TimeValue("00:00:01")
    DoEvents

    Application.SendKeys "s", True
    Application.Wait Now + TimeValue("00:00:02")
    Application.SendKeys "y", True

'''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    .Quit

End With

Dim objFile As Scripting.File: Set objFile = objFso.GetFile(strSaveAsFullPath)

Set GetTransworldFile = objFile

Set objIE = Nothing
Set objFso = Nothing

结束功能

推荐答案

我终于弄清楚了如何做到这一点,我使用XMLHTTP并设置了各种标头来伪装成合法的浏览器,然后提取了viewstate和事件验证,用它来发布表单数据的各个位.我很高兴,我一整天都在为此工作:)

I finally worked out how to do this, i used XMLHTTP and set various headers to masquerade as a legitimate browser, i then pulled the viewstate and the event validation and used that to post the various bits of form data. i am so happy, i spent most of my day working on this :)

我不会发布我的代码,因为它有点混乱,但是如果其他人遇到这种问题,则应下载并使用Fiddler从浏览器捕获HTTP帖子和响应,然后使用脚本尝试进行模拟浏览器通过设置相同的标题和表单数据来做到这一点,这应该很容易.

i wont post my code as it is in a bit of mess but if anyone else comes across this kind of problem you should download and use Fiddler to capture the HTTP posts and responses from the browser and then using your script try and simulate the browser by setting the same headers and form data, do that and it should be easy..

这篇关于使用InternetExplorer.Applicaion获取响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆