Jump to content

Catching generated by server report-file in IE


Keiga
 Share

Recommended Posts

Need some help with Autoit + IE9

There is a one site in my network. That site have a button with pdf icon on it. After mouse click - server will use inner function to generate a pdf report and IE download window will appear. How can i catch this file using autoit and escape IE "save as" window?

Button info from DebugBar:

<IMG title="Save as PDF" onclick="prj.saveReportAs('table1.rdl', 'pdf', 'Report File', getParamsXml())" src="img/icon/pdf.gif" width=16 height=16>

I can't use InetGet because i don't have a direct link to file.

Link to comment
Share on other sites

I can't give url. it's inner website at my working network. I try to use autoit to automate button pressing in IE download window, but it will be my last resort.

I try using inetGet, but without direct url to file it's useless. in one forum I was advised to use redirection script with WinHttp or TCP functions, but I could not understand it by myself.

Example using WinHttp:

$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Option(6) = False ;WinHttpRequestOption_EnableRedirects
$oHTTP.Open("GET", "test-site.com")
$oHTTP.Send()
$oHTTP.WaitForResponse
$sNewLocation = $oHTTP.GetResponseHeader("Location")
ConsoleWrite($sNewLocation & @LF)

Example using TCP:

$sHead = _HTTPGetResponse("test-site.som", "/load/0-0-1-52-20", "HEAD")

If StringRegExp($sHead, "(?i)Content-Type:(.*?)html") Then
$sHead = _HTTPGetResponse("creator-lab.ucoz.ru", "/load/0-0-1-52-20", "GET")
EndIf

$sNewLocation = StringRegExpReplace($sHead, '(?s).*\r?\nLocation:\h*([^\r\n]+)\r?\n.*', '\1')
MsgBox(64, 'Title', 'Location: ' & @CRLF & $sNewLocation)

Func _HTTPGetResponse($sHost, $sPage, $sRequest = "HEAD")
TCPStartup()

Local $sName_To_IP = TCPNameToIP($sHost)
Local $iSocket = TCPConnect($sName_To_IP, 80)

If $iSocket = -1 Then
TCPShutdown()
Return SetError(1, 0, "")
EndIf

Local $sCommand = $sRequest & " " & $sPage & " HTTP/1.1" & @CRLF
$sCommand &= "Host: " & $sHost & @CRLF
$sCommand &= "User-Agent: AutoIt/" & @AutoItVersion & " (Windows; U; Windows NT 5.1; en-US; rv:1.8.1)" & @CRLF
$sCommand &= "Referer: " & $sHost & @CRLF
$sCommand &= "Connection: close" & @CRLF & @CRLF

Local $BytesSent = TCPSend($iSocket, $sCommand)

If $BytesSent = 0 Then
TCPShutdown()
Return SetError(2, @error, 0)
EndIf

Local $sRecv = "", $sCurrentRecv

While 1
$sCurrentRecv = TCPRecv($iSocket, 16)
If @error <> 0 Then ExitLoop
If $sCurrentRecv <> "" Then $sRecv &= $sCurrentRecv
WEnd

TCPCloseSocket($iSocket)
TCPShutdown()

Return $sRecv
EndFunc
Edited by Keiga
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...