Announcement

Collapse
No announcement yet.

WINHHTP COM Examples

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

  • #21
    Please disregard the error I reported above. I finally figured out where MY error was haha. Thank You

    Comment


    • #22
      Yep that was it!

      Comment


      • #23
        1 No error if folder or file does not exist?
        2 If downloading from a protected page is user name and password that of the protected page?

        ' Opens an HTTP connection to an HTTP resource
        pWHttp.Open "GET", "http://www.microsoft.com/library/homepage/images/DOESNOTEXIST.gif"
        ' Sends an HTTP request to the HTTP server
        pWHttp.Send
        ' Wait for response with a timeout of 5 seconds
        iSucceeded = pWHttp.WaitForResponse(5)

        Comment


        • #24
          Download from protected folders.
          Works with protected folders and will return file not found or Unauthorized.
          Code:
          #INCLUDE "httprequest.inc"
          ' https://forum.powerbasic.com/forum/jose-s-corner/source-code-ab/51694-winhhtp-com-examples
          %FALSE=0
          
          FUNCTION PBMAIN
          
           LOCAL wsFullPath,wsUsername,wsPassword,wsDataReturned,wsStatus AS WSTRING
          
           wsFullPath = "https://powerbasic.com/protectedfolder/protectedfile.exe"
           wsUserName = ""
           wsPassword = ""
           wsStatus= Download(wsFullPath, wsUserName, wsPassword,wsDataReturned)
          
           IF wsStatus = "OK" THEN
            ? USING$("Downloaded (#, bytes)",LEN(wsDataReturned)),%MB_SYSTEMMODAL,"Success"
           ELSE
            ? wsStatus,%MB_ICONERROR OR %MB_SYSTEMMODAL,"Download Failed"
           END IF
          
          END FUNCTION
          '===============================================================================================
          FUNCTION Download(wsFullPath       AS WSTRING,_
                        wsUserName           AS WSTRING,_
                        wsPassword           AS WSTRING,_
                        wsDataReturned       AS WSTRING) AS WSTRING
          
           RESET wsDataReturned
           DIM pHttpReq AS IWinHttpRequest
           pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
           IF ISNOTHING(pHttpReq) THEN
            ? "WinHttpRequest.5.1 failure",%MB_ICONERROR OR %MB_SYSTEMMODAL,"Download"
            EXIT FUNCTION
           END IF
           pHttpReq.Open "GET", wsFullPath, %FALSE
           pHttpReq.SetCredentials wsUserName, wsPassword, %HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
           pHttpReq.Send
           IF pHttpReq.StatusText <> "OK" THEN
            BEEP
           ELSE
            wsDataReturned = pHttpReq.ResponseText
           END IF
           FUNCTION = pHttpReq.StatusText
           pHttpReq = NOTHING
          END FUNCTION

          Comment

          Working...
          X