Jump to content

Downloading files from https sites using inetget


Recommended Posts

Hi Guys, I need help. I have searched the forum before posting and i couldn't find anything. The code below works fine when downloading files from "http" sites, but when trying to download from "https" sites, no files are downloaded. I tried different sites and I experience the same problem everywhere. Is there something I'm missing or doing wrong? Please note that I'm not a programmer and I'm new to this. I'm just using logic wherever i can to get things done. your help will be highly appreciated.

 

#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

; Download a file in the background.
; Wait for the download to complete.


Example()

Func Example()
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = "d:\"

    ; Download the file in the background with the selected option of 'force a reload from the remote site.'
    Local $hDownload = InetGet("https://en.wikipedia.org/wiki/HTTPS#/media/File:Internet2.jpg", $sFilePath& "Internet2.jpg", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

    ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

    ; Retrieve the number of total bytes received and the filesize.
    Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
    Local $iFileSize = FileGetSize($sFilePath&"Internet2.jpg")

    ; Close the handle returned by InetGet.
    InetClose($hDownload)

    ; Display details about the total number of bytes read and the filesize.
    MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _
            "The total filesize: " & $iFileSize)

    ; Delete the file.
    ;FileDelete($sFilePath)
EndFunc   ;==>Example

 

Link to post
Share on other sites

I was just using Wikipedia as an example because to actually get the files from the site i want i have to login. the logging in and navigating to the correct web page part is sorted. I'm actually trying to download files from https://rda.ucar.edu/. file sizes are between 17 and 20 MB. I tried using your code but still no luck. I've seen people mentioning things like cookies for sites that require authentication, etc. I don't understand what they were saying but maybe that's where my problem is.

My login in code is attached. i will pm my credentials. link to the file i want to download is on the code.

 

login&navigate.au3

Link to post
Share on other sites

Hi again,

just found this tip elsewhere here  in the forum...

inetget ("https://" & $user & ":" & $pass & "@www.mywebsite.com)

can you try something like...

Local $hDownload = InetGet("https://" & $User & ":" & $Pwd & "@rda.ucar.edu/data/ds083.2/grib2/2017/2017.07/fnl_20170724_06_00.grib2", $sFilePath & "fnl_20170724_06_00.grib2", $INET_DOWNLOADWAIT);, $INET_FORCERELOAD)

...with your username and password?

good luck!

Link to post
Share on other sites
20 hours ago, MarxBros said:

Hi again,

just found this tip elsewhere here  in the forum...

inetget ("https://" & $user & ":" & $pass & "@www.mywebsite.com)

can you try something like...

Local $hDownload = InetGet("https://" & $User & ":" & $Pwd & "@rda.ucar.edu/data/ds083.2/grib2/2017/2017.07/fnl_20170724_06_00.grib2", $sFilePath & "fnl_20170724_06_00.grib2", $INET_DOWNLOADWAIT);, $INET_FORCERELOAD)

...with your username and password?

good luck!

Will try this when i get home, thank you MarxBros

Link to post
Share on other sites
21 hours ago, MarxBros said:

Hi again,

just found this tip elsewhere here  in the forum...

inetget ("https://" & $user & ":" & $pass & "@www.mywebsite.com)

can you try something like...

Local $hDownload = InetGet("https://" & $User & ":" & $Pwd & "@rda.ucar.edu/data/ds083.2/grib2/2017/2017.07/fnl_20170724_06_00.grib2", $sFilePath & "fnl_20170724_06_00.grib2", $INET_DOWNLOADWAIT);, $INET_FORCERELOAD)

...with your username and password?

good luck!

Hi MarxBros,

I tried this method and it doesnt seem to work. the code just runs continually without any file being downloaded.. how can i use IE object as Danp2 suggested above?

Regards

Link to post
Share on other sites
1 hour ago, Dante_t said:

Hi Danp2, which method are you referring to? can you please share your code if ystill have?

You create a hidden GUI containing an embedded IE object. Use this object to log into the website and navigate to the correct page. Retrieve links to be downloaded and then use InetGet to perform the download.

Like this --

; *******************************************************
; Download files from website
; *******************************************************
Func RetrieveFiles()
Local $oButton, $oElement, $oForm, $oFrame, $oTable, $aTableData, $oLinks, $oLink, $iNumLinks
Local $filename, $i, $trs, $href, $created, $array

    $IsDownloaded = False

    _FileWriteLog($LogFile, "Logging into website")

    ; Create embedded IE object
    $oIE = _IECreateEmbedded()

    ; Dummy GUI
    GUICreate("Dummy", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2)
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    GUISetState(@SW_SHOW)

    ; Open instance of website
    _IENavigate ($oIE, $Url)

    If @error Then
        ErrNotify("_IENavigate error. Errorcode = " & @error)
        Return
    EndIf

    ; Log into website
    $oForm = _IEFormGetCollection($oIE,0)

    If @error Then
        ErrNotify("_IEFormGetCollection error. Errorcode = " & @error)
        Return
    EndIf

    $oElement = _IEFormElementGetObjByName($oForm, "user")

    If @error Then
        ErrNotify("_IEFormElementGetObjByName (user) error. Errorcode = " & @error)
        Return
    EndIf

    _IEFormElementSetValue($oElement,$User)

    $oElement = _IEFormElementGetObjByName($oForm, "password")

    If @error Then
        ErrNotify("_IEFormElementGetObjByName (password) error. Errorcode = " & @error)
        Return
    EndIf

    _IEFormElementSetValue($oElement,$Pass)

    _IEFormSubmit($oForm)
    _IELoadWait ($oIE)

    _FileWriteLog($LogFile, "Switching to Downloads tab")

    ; Switch to Downloads tab
    _IELinkClickByText($oIE, "Downloads")

    If @error Then
        ErrNotify("_IELinkClickByText (Downloads) error. Errorcode = " & @error)
        Return
    EndIf

    $oForm = _IEFormGetObjByName($oIE, "frmSearch")

    If @error Then
        ErrNotify("_IEFormGetObjByName (Downloads) error. Errorcode = " & @error)
        Return
    EndIf

    $oElement = _IEFormElementGetObjByName($oForm, "lstboxes")

    If @error Then
        ErrNotify("_IEFormElementGetObjByName (Downloads) error. Errorcode = " & @error)
        Return
    EndIf

    For $i = 0 To $oElement.Length - 1
        _IEFormElementOptionSelect($oElement, $i, 1, "byIndex", 1)
        _IELoadWait($oIE)

        _FileWriteLog($LogFile, "Retrieving links (" & $i & ")")

        $oLinks = _IEGetObjByName($oIE, "file_list_link", -1)

        If @error Then
            ErrNotify("_IEGetObjByName (Downloads) error. Errorcode = " & @error)
            Return
        EndIf

        $iNumLinks = @extended

        For $oLink In $oLinks
            $href = $oLink.href

            $filename = StringTrimLeft($href, StringInStr($href, "*", 0, -1))

            If StringRegExp($filename, "(?i)\.(?:tif|txt)$") Then
                ; Make sure file wasn't already processed
                If Not FileExists($ProcessedDir & $filename) Then
                    $IsDownloaded = True

                    _FileWriteLog($LogFile, "Retrieving file: " & $filename)

                    ; Retrieve file

                    ConsoleWrite($InDir & $filename & @CRLF)

                    InetGet($href, $InDir & $filename, 1)

                    If @error Then
                        ErrNotify("InetGet (Downloads) error. Errorcode = " & @error)
                        Return
                    EndIf
                EndIf
            EndIf
        Next

        ; Reselect the desired objects due to prior page reload
        $oForm = _IEFormGetObjByName($oIE, "frmSearch")

        If @error Then
            ErrNotify("_IEFormGetObjByName (Downloads) error. Errorcode = " & @error)
            Return
        EndIf

        $oElement = _IEFormElementGetObjByName($oForm, "lstboxes")

        If @error Then
            ErrNotify("_IEFormElementGetObjByName (Downloads) error. Errorcode = " & @error)
            Return
        EndIf
    Next

    _IELinkClickByText($oIE, "Log off")

    ; Release GUI
    GUIDelete()

    _FileWriteLog($LogFile, "Completed File Retrieval")
EndFunc

 

Link to post
Share on other sites

Huge credits to trancexx for the wonderful  WinHttp.au3 , this works nice - using the *appropriate* credentials  :)

#include "WinHttp.au3"

$sServerAddress = "https://rda.ucar.edu"
$sGeneratorLocation = "/cgi-bin/login"

; sorry, these are private
$sEmail = "xxx@xxx"
$sPassword = "xxxxxxxx"

$hOpen = _WinHttpOpen()

; get access cookie
$hConnect = _WinHttpConnect($hOpen, $sServerAddress)
_WinHttpSimpleSSLRequest($hConnect)
_WinHttpCloseHandle($hConnect) 

; build and fill the login form
$sForm = _
        '<form action="' & $sServerAddress & $sGeneratorLocation & '" method="post">' & _
        '   <input name="email" />' & _
        '   <input name="passwd" />' & _
        '   <input name="remember" />' & _
        '   <input name="do" />' & _
        '   <input name="url" />' & _
        '</form>'
$hConnect = $sForm 

$sReturned = _WinHttpSimpleFormFill($hConnect, $hOpen, _
        Default, _
        "name:email", $sEmail, _
        "name:passwd", $sPassword, _ 
        "name:remember", "on", _
        "name:do", "login", _
        "name:url", "/")
If @error Then
    MsgBox(4096, "Error", @error) ; ref. WinHttp.chm
Else
    MsgBox(4096, "OK", "login successful, now download")

; download
  $sFile = "fnl_20170724_06_00.grib2"
  $sTarget = "data/ds083.2/grib2/2017/2017.07/" & $sFile

  $hConnect = _WinHttpConnect($hOpen, $sServerAddress)
  $hRequest = _WinHttpOpenRequest($hConnect, "GET", $sTarget)  
  _WinHttpSendRequest($hRequest)
  _WinHttpReceiveResponse($hRequest)
  If _WinHttpQueryDataAvailable($hRequest) Then

    $headers = _WinHttpQueryHeaders($hRequest)
    $Length = StringRegExpReplace($headers, '(?s).*Content-Length:\h*(\d+).*', "$1") 
    Local $bChunk, $bData = Binary("")

    ProgressOn($sFile, "Downloading", "0 %")
    While 1
         $bChunk = _WinHttpReadData($hRequest, 2, 8192) ; binary
         If @error Then ExitLoop
         $bData &= $bChunk
         $percent = Int((BinaryLen($bData)/$Length)*100)
         ProgressSet($percent, "Downloading", $percent & " %")
     WEnd
     ProgressSet(100, "Done !", "100 %")
     FileWrite(@scriptdir & "\" & $sFile, $bData)
     Sleep(1000)
     ProgressOff()
  Else
      MsgBox(48, "", "connection error")
  EndIf

; close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
EndIf

 

Link to post
Share on other sites

Hi Danp2, i wanted to use your code but i just didnt know where to edit it for it to do what i require it to do. Thank you

Hi Mikell, I used this code. the logging in was successful. the file i would like to download is 17MB in size but this code only downloads 440bytes file. the content of the file downloaded is as follows:

"Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
 Instead use the HTTPS scheme to access this URL, please"
 

 

Is there something im not doing right?

 

Regards

Dante

Edited by Dante_t
big qoutes
Link to post
Share on other sites
#include "WinHttp.au3"

$sServerAddress = "https://rda.ucar.edu"
$sGeneratorLocation = "/cgi-bin/login"

$sEmail = "xxxxxxx@xxxxxx"
$sPassword = "xxxxxxx"

$hOpen = _WinHttpOpen()

; collect access cookie first
$hConnect = _WinHttpConnect($hOpen, $sServerAddress)
_WinHttpSimpleSSLRequest($hConnect)
_WinHttpCloseHandle($hConnect) 

; build and fill the login form
$sForm = _
        '<form action="' & $sServerAddress & $sGeneratorLocation & '" method="post">' & _
        '   <input name="email" />' & _
        '   <input name="passwd" />' & _
        '   <input name="remember" />' & _
        '   <input name="do" />' & _
        '   <input name="url" />' & _
        '</form>'
$hConnect = $sForm 

$sReturned = _WinHttpSimpleFormFill($hConnect, $hOpen, _
        Default, _
        "name:email", $sEmail, _
        "name:passwd", $sPassword, _ 
        "name:remember", "on", _
        "name:do", "login", _
        "name:url", "/")
If @error Then
    MsgBox(4096, "Error", @error)
Else
    MsgBox(4096, "OK", "login successful, now download")





; download
  $sFile = "fnl_20170724_06_00.grib2"
  $sTarget = "data/ds083.2/grib2/2017/2017.07/" & $sFile

  _WinHttpCloseHandle($hConnect)
  $hConnect = _WinHttpConnect($hOpen, $sServerAddress)
  $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "GET", $sTarget)
  If _WinHttpQueryDataAvailable($hRequest) Then

    $headers = _WinHttpQueryHeaders($hRequest)
    $Length = StringRegExpReplace($headers, '(?s).*Content-Length:\h*(\d+).*', "$1") 
    Local $bChunk, $bData = Binary("")

    ProgressOn($sFile, "Downloading", "0 %")
    While 1
         $bChunk = _WinHttpReadData($hRequest, 2, 8192) ; binary
         If @error Then ExitLoop
         $bData &= $bChunk
         $percent = Int((BinaryLen($bData)/$Length)*100)
         ProgressSet($percent, "Downloading", $percent & " %")
     WEnd
     ProgressSet(100, "Done !", "100 %")
     FileWrite(@scriptdir & "\" & $sFile, $bData)
     Sleep(1000)
     ProgressOff()
  Else
      MsgBox(48, "", "connection error")
  EndIf

; close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
EndIf
Link to post
Share on other sites
Just now, Dante_t said:
#include "WinHttp.au3"

$sServerAddress = "https://rda.ucar.edu"
$sGeneratorLocation = "/cgi-bin/login"

$sEmail = "xxxxxxx@xxxxxx"
$sPassword = "xxxxxxx"

$hOpen = _WinHttpOpen()

; collect access cookie first
$hConnect = _WinHttpConnect($hOpen, $sServerAddress)
_WinHttpSimpleSSLRequest($hConnect)
_WinHttpCloseHandle($hConnect) 

; build and fill the login form
$sForm = _
        '<form action="' & $sServerAddress & $sGeneratorLocation & '" method="post">' & _
        '   <input name="email" />' & _
        '   <input name="passwd" />' & _
        '   <input name="remember" />' & _
        '   <input name="do" />' & _
        '   <input name="url" />' & _
        '</form>'
$hConnect = $sForm 

$sReturned = _WinHttpSimpleFormFill($hConnect, $hOpen, _
        Default, _
        "name:email", $sEmail, _
        "name:passwd", $sPassword, _ 
        "name:remember", "on", _
        "name:do", "login", _
        "name:url", "/")
If @error Then
    MsgBox(4096, "Error", @error)
Else
    MsgBox(4096, "OK", "login successful, now download")





; download
  $sFile = "fnl_20170724_06_00.grib2"
  $sTarget = "data/ds083.2/grib2/2017/2017.07/" & $sFile

  _WinHttpCloseHandle($hConnect)
  $hConnect = _WinHttpConnect($hOpen, $sServerAddress)
  $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "GET", $sTarget)
  If _WinHttpQueryDataAvailable($hRequest) Then

    $headers = _WinHttpQueryHeaders($hRequest)
    $Length = StringRegExpReplace($headers, '(?s).*Content-Length:\h*(\d+).*', "$1") 
    Local $bChunk, $bData = Binary("")

    ProgressOn($sFile, "Downloading", "0 %")
    While 1
         $bChunk = _WinHttpReadData($hRequest, 2, 8192) ; binary
         If @error Then ExitLoop
         $bData &= $bChunk
         $percent = Int((BinaryLen($bData)/$Length)*100)
         ProgressSet($percent, "Downloading", $percent & " %")
     WEnd
     ProgressSet(100, "Done !", "100 %")
     FileWrite(@scriptdir & "\" & $sFile, $bData)
     Sleep(1000)
     ProgressOff()
  Else
      MsgBox(48, "", "connection error")
  EndIf

; close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
EndIf

This code worked for me. Thank you Mikell for the solution and thank you everyone who tried to help. much appreciated.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By rudi
      Hello,
      is there a way to use inetget() to catch the content of an 404 error page returned by the web server?
       
      $URL="https://www.autoitscript.com/ThisPathDoesntExist" $content=InetGet($url,"c:\temp\xxx.html",1+2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = "' & $content & """" & @CRLF & "@Extended: """ & @extended & """" & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console  
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\löschmich\xxx.au3" /UserParams +>15:27:05 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0 Keyboard:00000407 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0407) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\temp\löschmich\xxx.au3 +>15:27:05 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\löschmich\xxx.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop @@ Debug(6) : $content = "0" @Extended: "0" >Error code: 13 +>15:27:05 AutoIt3.exe ended.rc:0 +>15:27:05 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.9361  
      The browser (I use Chrome) is displaying this 404 page: (That's what I'd like to catch)
      Not Found The requested URL /ThisPathDoesntExist was not found on this server. html code (Browser ctrl+u):
      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /ThisPathDoesntExist was not found on this server.</p> </body></html>  
      Wireshark response 404 packet:
      Hypertext Transfer Protocol HTTP/1.1 404 Not Found\r\n Server: nginx\r\n Date: Wed, 06 Apr 2022 13:34:26 GMT\r\n Content-Type: text/html; charset=iso-8859-1\r\n Content-Length: 217\r\n Connection: keep-alive\r\n Vary: Accept-Encoding\r\n \r\n [HTTP response 1/1] [Time since request: 0.056074000 seconds] [Request in frame: 1476] [Request URI: http://www.autoitscript.com/ThisPathDoesntExist] File Data: 217 bytes Line-based text data: text/html (7 lines) <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /ThisPathDoesntExist was not found on this server.</p> </body></html> any suggestions appreciated,
      <edit> also tried _inetgetsource() and inetread() </edit>
      Rudi
    • By Jahar
      I have an AutoIT script It monitors 2 websites for content that applys to me and the services that I provide. One site is : www.Freelancer.com The other: www.PeoplePerHour.com Both sites publish new jobs on their site hourly or so. My AutoIT app, will view those sites and present new jobs to me in a grid that pops up on my screen. Lately, the app has stopped showing me any jobs from PeoplePerHour.
       
      For freelancer.com,  Inetget is giving full html but for peopleperhour, now its not coming.
      Func _CheckPPH()
          Local Static $hTimer = 0
          Local Static $hDownload = 0
          Local $aTitlesandUrls = 0
          Local Static $sTempFile = ""
          If $hTimer = 0 Then $hTimer = TimerInit()
          If $hDownload = 0 Then
              $sTempFile = _WinAPI_GetTempFileName(@TempDir)
              ConsoleWrite("Checking PPH..." & @CRLF)
              ConsoleWrite(">Downloading..." & @CRLF)
      ;~         $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
              $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD)
      ;~         Return 0
          EndIf
      ;~     Sleep(30)
      ;~     Local $isCompleted = InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
      ;~     Local $isError = InetGetInfo($hDownload, $INET_DOWNLOADERROR)
      ;~     Sleep(30)
      ;~     If TimerDiff($hTimer) > 3000 And $isError Then
      ;~         ConsoleWrite("!PPH Fail" & @CRLF)
      ;~         InetClose($hDownload)
      ;~         $hDownload = 0
      ;~         Return 0
      ;~     EndIf
      ;~     Sleep(30)
          Local $Show = 0
      ;~     If TimerDiff($hTimer) > 3000 And $isCompleted Then
          If $hDownload > 0 Then
              ConsoleWrite("+Downloaded..." & @CRLF)
              Local $sPPHHtml = FileRead($sTempFile)
              $aTitlesandUrls = _StringBetween($sPPHHtml, '"title">' & @LF, 'time>')
      ;~         _ArrayDisplay($aTitlesandUrls)
              Local $aPPH[0][4]
              Local $sTitle = ""
              Local $sUrl = ""
              Local $sID = ""
              Local $sDate = ""
              Local $iRet=0
              Sleep(30)
              For $i = 0 To UBound($aTitlesandUrls) - 1
                  $sTitle = _StringBetween($aTitlesandUrls[$i], '<a title="', '" class')
                  $sUrl = _StringBetween($aTitlesandUrls[$i], 'href="', '">')
                  $sDate = _GetDate($aTitlesandUrls[$i])
                  If IsArray($sTitle) And IsArray($sUrl) Then
                      $sID = _GetID($sUrl[0])
      ;~                 _ArrayAdd($aPPH, $sDate & "|" & $sTitle[0] & "|" & $sUrl[0] & "|" & $sID)
                      $iRet = _BuildPopupsPPH($sID, $sDate, "PPH: " & $sTitle[0], $sUrl[0])
                      If $iRet Then $Show+=1
                  EndIf
              Next
              Sleep(30)
      ;~         If $Show > 0 Then ShowLatestJobs()
      ;~         _ArrayDisplay($aPPH)
              FileDelete($sTempFile)
              InetClose($hDownload)
              $hDownload = 0
              $hTimer = 0
              Return $Show
          EndIf
          Sleep(30)
      EndFunc   ;==>_CheckPPH
    • By argumentum
      I can TCP/IP in AutoIt, hence, make a HTTP deamon. Now, how can I HTTPS to use SSL !??
      Well, Apache has this "mod_proxy.so" module that can let me have SSL and what not is in Apache.
      All that is needed is to tell Apache what I wanna do by editing httpd.conf .
      # Implements a proxy/gateway for Apache. # 1. Open /Applications/XAMPP/etc/httpd.conf # 2. Enable the following Modules by removing the # at the front of the line. # - LoadModule rewrite_module modules/mod_rewrite.so # - LoadModule proxy_module modules/mod_proxy.so # - LoadModule proxy_http_module modules/mod_proxy_http.so # # 3. Copy and Paste below to the bottom of httpd.conf # <IfModule mod_proxy.c> ProxyRequests On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyVia Off ProxyPreserveHost Off ProxyPass /home/ http://127.0.0.1:84/home/ ProxyPassReverse /home/ http://127.0.0.1:84/home/ SetEnv proxy-nokeepalive 1 # ..since we are not using "keep-alive", we are using "close" </IfModule> ...et voila  
      I'm using XAMPP ( https://www.apachefriends.org/download.html )
      and this is my solution to avoid coding in PHP, as I feel more comfortable coding in AutoIt.
      A "muli-thread or concurrency" can be done by forking the socket ( https://www.autoitscript.com/forum/topic/199177-fork-udf-ish/ )
      but responses are under 20 ms., so I feel fine with a single thread.
      I modified an example ( attached below ), so can try out the concept.
      PS: I am not an Apache guru. I just discovered this and it opens a world of possibilities. In my case, I'm thinking of an API to query SQLite 
      PS2: I'm not gonna make Poll but do click like if you do  
       
      201673-json-http-post-serverlistener.au3
    • By Melque_Lima
      A little help here please !?
      I'm trying to parse a file but the function is not working well! i think there is some thind doing wrong at FileRead()
      Obs: username,password and API link below is fictitious
      ConsoleWrite(">POST METHOD UPLOADING LOCAL IMAGE<" & @CRLF) _PostMethodTest() Func _PostMethodTest() Local Const $sAPIKey = '8f1e0a750088957' Local $sBoundary = "--------Boundary" Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF Local $sData = '' Local $sFileName="image.jpg" Local $sFilePath="C:\Users\DELL\Desktop\" & $sFileName Local $hFile=FileOpen($sFilePath,16);16=$FO_BINARY Local $sFileData=FileRead($hFile) FileClose($hFile) $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="myImage"; filename="' & $sFileName & '"' & @CRLF $sData &= 'Content-Type: application/upload' & @CRLF & @CRLF $sData &= BinaryToString($sFileData,0) & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="username"' & @CRLF & @CRLF $sData &="myuserName" & @CRLF $sData &= "--" & $sBoundary & @CRLF $sData &= 'Content-Disposition: form-data; name="password"' & @CRLF & @CRLF $sData &="MyPassword" & @CRLF $sData &=$sBoundary & "--" ConsoleWrite($sData) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "http://myapi", False) $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $sBoundary) $oHTTP.SetRequestHeader("apikey", $sAPIKey) $oHTTP.Send(StringToBinary($sData,1)) Local $sReceived = $oHTTP.ResponseText ConsoleWrite($sReceived & @CRLF) EndFunc ;==>_PostMethodTest  

    • By Tersion
      Why I can't get more than two simultaneously background downloads?
      Simultaneously background downloads with InetGet() works! It was just server limitation from which I downloaded files.
×
×
  • Create New...