Jump to content

nicero

Members
  • Posts

    4
  • Joined

  • Last visited

nicero's Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. I'm an AutoIt absolute beginner and I'm working (hard) to manage to download and upload files from a server. The problem I'm facing, I suppose, it's due to the fact that I'm behind a proxy. I read carefully every single post on this forum about downloading / uploading files. I know about HttpSetProxy and INetGet but although I can get proxy settings from the Windows' registry, I'm not able to download anything with INetGet. None of the following HttpSetProxy (one of the three alternatives of course) settings work: Local $sProxyServer = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") Local $sProxyOverride = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride") HttpSetProxy(0) HttpSetProxy(0, $sProxyServer) HttpSetProxy(2, $sProxyServer) This is what I achieved up to now thanks to a useful user's post: DOWNLOAD (using WinHTTP) #include "WinHttp.au3" #include "WinHttpConstants.au3" #include <Array.au3> Opt("MustDeclareVars", 1) ; Internet Explorer proxy configuration for the current user: Global $aIEproxy = _WinHttpGetIEProxyConfigForCurrentUser() Global $sHost = "xxx.yyy.kkk.zzz" Global $sTarget = "image.jpg" Global $sDestination = @ScriptDir & "\image.jpg" ; Initialize and get session handle Global $hHttpOpen = _WinHttpOpen(Default, $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $aIEProxy[2], $aIEProxy[3]) If @error Then MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.") Exit 1 EndIf ; Get connection handle Global $hHttpConnect = _WinHttpConnect($hHttpOpen, $sHost) If @error Then MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.") _WinHttpCloseHandle($hHttpOpen) Exit 2 EndIf ; Specify the reguest Global $hHttpRequest = _WinHttpOpenRequest($hHttpConnect, Default, $sTarget) If @error Then MsgBox(48, "Error", "Error creating an HTTP request handle.") _WinHttpCloseHandle($hHttpConnect) _WinHttpCloseHandle($hHttpOpen) Exit 3 EndIf ; Send request _WinHttpSendRequest($hHttpRequest) If @error Then MsgBox(48, "Error", "Error sending specified request.") _WinHttpCloseHandle($hHttpConnect) _WinHttpCloseHandle($hHttpOpen) Exit 4 EndIf ; Wait for the response _WinHttpReceiveResponse($hHttpRequest) ; Read if available Global $bChunk, $bData, $hFile If _WinHttpQueryDataAvailable($hHttpRequest) Then While 1 $bChunk = _WinHttpReadData($hHttpRequest, 2) ; read binary If @error Then ExitLoop $bData = _WinHttpSimpleBinaryConcat($bData, $bChunk) ; concat two binary data WEnd ; Save it to the file $hFile = FileOpen($sDestination, 26) FileWrite($hFile, $bData) FileClose($hFile) Else MsgBox(48, "Error occurred", "No data available. " & @CRLF) EndIf ; Close handles _WinHttpCloseHandle($hHttpRequest) _WinHttpCloseHandle($hHttpConnect) _WinHttpCloseHandle($hHttpOpen) Question #1. Any ideas why I'm not able to download with INetGet? Should I keep using WinHTTP? UPLOAD Thanks to an other precious post I managed to upload a file with the following code: $HTTPREQUEST_PROXYSETTING_PROXY = 2; $File = @ScriptDir & "\1.gif" $sHost = "xxx.yyy.kkk.zzz" $sFormAction = "/postdata.php" $hfile = FileOpen($File, 16) $sFileTypeName = StringRegExpReplace($File, '^.*\\', '') ; Get system proxy settings Local $sProxyServer = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") Local $sProxyOverride = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride") While 1 $data = FileRead($hfile, 500000) ;Read file in 500Kb chunks If @error Then ExitLoop Global $Data2 = StringTrimLeft($data,2) SendPost() WEnd Func SendPost() $oRequest = ObjCreate('WinHttp.WinHttpRequest.5.1') $oRequest.SetProxy( $HTTPREQUEST_PROXYSETTING_PROXY, $sProxyServer, $sProxyOverride); $oRequest.Open('POST', 'http://' & $sHost & $sFormAction, 0) $oRequest.SetRequestHeader('User-Agent', 'Mozilla/4.0 (Windows XP 5.1)') $oRequest.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded') $oRequest.SetRequestHeader('Host', $sHost) $oRequest.Send('filename=' & $sFileTypeName & '&data=' & $Data2) $sData = $oRequest.ResponseText ConsoleWrite($File & @CRLF) EndFunc Which calls the following PHP <?php $fileName = $_POST['filename']; $binaryData = $_POST['data']; $fh = fopen("./$fileName", 'a+b'); fwrite($fh, pack("H*" , $binaryData)); fclose($fh); ?> Question #2. As said I'm an absolute beginner. If I'm going to use WinHTTP for downloading would someone please translate the above upload code to work with WinHTTP to keep code consistency and coherency? I found >this post but it didn't worked altough I did set the proxy. Thank you
  2. ; Gets proxy settings from Windows registry #include <MsgBoxConstants.au3> Local $sProxyServer = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") Local $sProxyOverride = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride") MsgBox($MB_SYSTEMMODAL, "Proxy", $sProxyServer & @CRLF & $sProxyOverride)
  3. Patching EXEs is a common practice since the earliest ages of PCs, when networks were not as fast as now and disk space was not as large as today. The logic at the base of patching an EXE is that you have to have a program that gets the differences between the old EXE and the new EXE and builds a third EXE that will go to patch the old EXE. Two good softwares that do this job are xdelta and bsdiff.
  4. I frequently copy some text from a PDF file and paste it inside some fields in a Excel userform. I would like a software (AutoIt or others) that permits me to paste the selected text in the PDF to the correct Excel userform field. I was thinking about something that works like this: 1. I select/highlight some text in the PDF file 2. I press a combination of keys 3. the software pastes the text into the - let's say - 'title' field of the Excel userform 4. I select some other text in the PDF file 5. I press an other combination of keys 6. the software pastes the text in to the 'description' field of the Excel userform I'm not an AutoIt guru. Can you post me some code please? Thank you very much
×
×
  • Create New...