Jump to content
Sign in to follow this  
Keiga

Catching generated by server report-file in IE

Recommended Posts

Keiga

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.

Share this post


Link to post
Share on other sites
Jury

Might help if you can give the url for the page with this link on it. What have you tried so for?

Edited by Jury

Share this post


Link to post
Share on other sites
Keiga

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.