Announcement

Collapse
No announcement yet.

Use of HTTPS fails

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of HTTPS fails

    I am trying to fetch a .jpg-file from : https://ystad.se/webkamera/KameraS1.jpg
    Code:
    #DEBUG DISPLAY ON
    #DEBUG ERROR ON
    #BREAK ON
    #COMPILE EXE
    #DIM ALL
    #COMPILER PBCC
    
    FUNCTION PBMAIN() AS LONG
    
        DIM BUFFER                          AS STRING
        DIM FILE_DATA                       AS STRING
        DIM URL_FILE                        AS STRING
        DIM URL_SITE                        AS STRING
    
    CONTACTING::
        URL_SITE = "ystad.se"
        URL_FILE = "https://ystad.se/webkamera/KameraS1.jpg"
        Tcp Open "HTTP" At URL_SITE As #1 TimeOut 60000
        TCP PRINT #1, "GET " + URL_FILE
        Tcp Print #1, ""
        Tcp Print #1, ""
    
    FETCHING_START:
        FILE_DATA = ""
    
    FETCHING_NEXT:
        TCP RECV #1, 4096, BUFFER
        FILE_DATA = FILE_DATA + BUFFER
        IF LEN(BUFFER) > 0 THEN GOTO FETCHING_NEXT
        TCP CLOSE #1
        PRINT FILE_DATA
    
    END FUNCTION
    But I receive this:
    <head><title>Document Moved</title></head>
    <body><h1>Object Moved</h1>This document may be found <a HREF="https:///webkamera/KameraS1.jpg">here</a></body>

    What am I doing wrong?

    /Fim W.
    Fim Wästberg

  • #2
    What am I doing wrong?
    You're not doing the security needed for HTTPS.


    TCP OPEN only takes care of OSI layer 4. The certificates and encryption are a higher layer.

    Hopefully someone here will suggest the APIs, or a third party DLL method that does it all down to, and including, opening the port.

    added - TCP OPEN "HTTP", opens port 80. HTTPS is port 443, All is of course learnable, But you're starting way back to do this project in near term. So I suggested API/DLL.

    Cheers,
    Dale

    Comment


    • #3

      Simple demo of URLDownloadToFile exported from system32\urlmon.dll - depreciated? - see previous discussion in forum.
      ( Tested ok with Win7 and Win10 )
      '
      Code:
      #DIM All
      #COMPILE Exe
      $URL = "https://ystad.se/webkamera/KameraS1.jpg"
      
      DECLARE FUNCTION URLDownloadToFile LIB "urlmon.dll" ALIAS "URLDownloadToFileA" _
         (BYVAL pCaller AS LONG, _
          szURL AS ASCIIZ, _
          szFileName AS ASCIIZ, _
          BYVAL dwReserved AS LONG, _
          BYVAL lpfnCB AS LONG) AS LONG
      
      FUNCTION DownloadFile(URL AS ASCIIZ, LocalFilename AS ASCIIZ) AS LONG
        DIM lngRetVal AS LONG
        lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
        IF lngRetVal = 0 THEN FUNCTION = 1
      END FUNCTION
      
      FUNCTION PBMAIN() AS LONG
       IF DownloadFile($URL, Exe.Path$ + "Downloaded.jpg") = 1 THEN
           MsgBox "Download successful!"
       ELSE
           MsgBox "Download failed!"
       END IF
      
      END FUNCTION
      '
      Rgds, Dave

      Comment


      • #4
        Totally fantastic. Here on the forum there are sorcerers, one named Dave Biggs.
        A big thanks.
        I will use the program to download .jpg files from a webcam that is updated 4 times per minute. These I will put together for a video clip "life in Ystad harbor for a day", if I succeed.
        Should I add a link here to the video clip?
        /Fim W.
        Fim Wästberg

        Comment


        • #5
          Here on the forum there are sorcerers..
          True - but mine's a different kind of pointy hat

          I would be interested to see the video. Hopefully not as eventful as the one recently recorded in Vienna!
          Rgds, Dave

          Comment


          • #6
            It works great, but Windows stores the image in some cache somewhere. When I download the file a while later, I get the same file that I downloaded the first time. Even after I restart the computer. According to Google, there is a cach here
            C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5
            But not in my computer.
            How do I solve this?
            /Fim W.



            Fim Wästberg

            Comment


            • #7
              Hi Fim,

              There is a solution to that problem presented by Mike Doty in the original forum posting.
              It checks and clears the Cache if previous download is found..
              '
              Code:
              #DIM All
              #COMPILE Exe
              $URL = "https://ystad.se/webkamera/KameraS1.jpg"
              
                DECLARE FUNCTION URLDownloadToFile LIB "urlmon.dll" ALIAS "URLDownloadToFileA" _
                  (BYVAL pCaller AS LONG, _
                    szURL AS ASCIIZ, _
                    szFileName AS ASCIIZ, _
                    BYVAL dwReserved AS LONG, _
                    BYVAL lpfnCB AS LONG) AS LONG
                DECLARE FUNCTION DeleteUrlCacheEntry LIB "wininet.dll" ALIAS "DeleteUrlCacheEntry"  (lpszUrlName AS ASCIIZ) AS LONG
              
                %ERROR_ACCESS_DENIED = 2
                %ERROR_FILE_NOT_FOUND =5
              
              FUNCTION DownloadFile(URL AS ASCIIZ, LocalFilename AS ASCIIZ) AS LONG
                DIM lngRetVal AS LONG
                    lngRetVal = DeleteURLCacheEntry(URL)  '1 = success
                  IF lngRetVal = 0 THEN
                      ? "Not in cache"
                  ELSEIF lngRetVal = 1 THEN
                    ? "Cache deleted"
                  ELSEIF lngRetVal = %ERROR_ACCESS_DENIED THEN        '(2)
                    ? "The file is locked or in use.  The entry is marked and deleted when the file is unlocked."
                  ELSEIF lngRetVal = %ERROR_FILE_NOT_FOUND THEN      '(5)
                    ? "File_Not_FOUND in cache"
                  ELSE
                    ? "DeleteURLCAcheEntry result:" + STR$(lngRetVal)
                  END IF
                  Reset lngRetVal
                lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
                IF lngRetVal = 0 THEN FUNCTION = 1
              END FUNCTION
              
              FUNCTION PBMAIN() AS LONG
               IF DownloadFile($URL, Exe.Path$ + "Downloaded.jpg") = 1 THEN
                   MsgBox "Download successful!"
               ELSE
                   MsgBox "Download failed!"
               END IF
              
              END FUNCTION
              '
              Rgds, Dave

              Comment


              • #8
                Hi Dave,
                Works perfect.
                Thanks.
                /Fim W.
                Fim Wästberg

                Comment


                • #9
                  A day in Ystad habor
                  www.fim.nu/Ystadhamn-2019-06-04.mp4
                  or
                  https://www.facebook.com/groups/1630...=group_comment
                  /Fim W.
                  Fim Wästberg

                  Comment


                  • #10
                    Terrible weather !
                    Rgds, Dave

                    Comment


                    • #11
                      FYI For Internet Explorer 11, which we have to use on certain websites.
                      I require every day along with a reboot before login, i have a batch file that is run immediately called ieclean.bat
                      In a start up batch file is a line "IF EXIST C:\WSBAT\IECLEAN.BAT START " " /min C:\WSBAT\IECLEAN.BAT
                      I have also put a link to the file on the desktop.


                      ieclean.bat
                      Code:
                      @ECHO OFF
                      C:
                      CD \
                      CLS
                      rem delete ie history  files
                      REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
                      CLS
                      rem delete ie cookies
                      REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
                      CLS
                      rem delete ie temporary internet files
                      REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
                      CLS
                      rem delete ie form data
                      REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
                      CLS
                      rem delete ie passwords
                      REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
                      CLS
                      rem delete ie all
                      RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
                      CLS
                      EXIT
                      p purvis

                      Comment

                      Working...
                      X