Announcement

Collapse
No announcement yet.

Server Exchange

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

  • #81
    Originally posted by Stuart McLachlan View Post
    Some examples to make this clear using Post 36 PB source
    and this PHP file
    are using "https://camcopng.com/getfile.php"
    or you created a new php

    Comment


    • #82
      Originally posted by Rod Macia View Post
      if you are using Stuat's Post function
      wsrequest = "select rowid from parts where rowid % 1000 = 0 order by rowid;"
      You should URL encode your request
      wsrequest = "select%20rowid%20from%20parts%20where%20rowid%20%25%201000%20%3D%200%20order%20by%20rowid%3B"
      If you are using POST, your request would normally should take the form"&key=value....." so that you can extract the data from the request.

      If you want to pass a single string sucvh as an SQL statement to a PHP page without using parameters keys and values, this works fine
      Code:
      wsrequest = "select rowid from parts where rowid % 1000 = 0 order by rowid;"
      and
      Code:
      <?php
      $data = file_get_contents('php://input');
      echo $data;
      ?>​​
      Click image for larger version  Name:	result2.jpg Views:	1 Size:	57.3 KB ID:	819045

      Comment


      • #83
        Originally posted by Rod Macia View Post

        are using "https://camcopng.com/getfile.php"
        or you created a new php
        Sorry, all of my subsequent PHP examples have only been run/tested locally on my machine (using http://test.test/argtest2.php , ..../argtest3.php etc ) I hadn't loaded them up to the Camco website.

        Added:
        OK, I've just uploaded the last one as argtest5.php to https://camcopng.com

        Code:
        <?php
        $data = file_get_contents('php://input');
        echo $data;
        ?>​​​

        Click image for larger version  Name:	result3.jpg Views:	0 Size:	57.8 KB ID:	819047

        Comment


        • #84
          Howdy, Stuart!

          But only if you have downloaded the wget utility and placed it in the same directory as your executable or in a directory in your path. :
          Yes, and a 3MB file at that - part of the unsatisfactory nature of that solution.

          For the case of a PHP that doesn't return anything (just takes an action on the server and closes), I really expected there would be a simple API to call the PHP.

          Well, not having found anything simpler to attract my attention, I'll focus on IWinHttpRequest. It appears to work and has the option of returning content without the kludge of saving a file.

          Thanks again!

          Comment


          • #85
            Originally posted by Gary Beene View Post
            For the case of a PHP that doesn't return anything (just takes an action on the server and closes), I really expected there would be a simple API to call the PHP.
            Depends on what you mean by "simple".
            There's the "flat" as opposed to "com" API WinInet.inc which has a HTTPSENDREQUEST function, but you still need to go through all the other bits of establising a connection to the server, populating the request and checking the result.

            José covered it fairly thoroughly years ago:
            https://forum.powerbasic.com/forum/j...ples#post51695

            Remember, what you are doing is talking to a web server, which has to pass your request on to a script, be it PHP,Perl, Python,CGI or whatever. You can't directly access anything executable on a web server other than the server service itself on Port 80 using the HTTP protocol.

            This seens pretty simple to me:
            '
            Code:
            FUNCTION PostData(wsURL AS WSTRING, wsData AS WSTRING) AS WSTRING
                'retrieve the posted data in your PHP file with:  $data = file_get_contents('php://input');
                DIM pHttpReq AS IWinHttpRequest
                pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
                IF ISNOTHING(pHttpReq) THEN FUNCTION = "WinHttpRequest.5.1 failure" :EXIT FUNCTION
                TRY
                   pHttpReq.Open "POST", wsURL, 0
                   pHttpReq.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                   pHttpReq.Send(wsData)
                   IF pHttpReq.StatusText = "" THEN
                        FUNCTION = "No response From Server" :EXIT FUNCTION
                   ELSE
                        FUNCTION =  pHttpReq.StatusText:EXIT FUNCTION
                   END IF
                CATCH
                    FUNCTION =  OBJRESULT$(OBJRESULT)
                END TRY
             END FUNCTION
            '


            or without any error checking,it's a "fairly simple api"
            '
            Code:
            FUNCTION PostData(wsURL AS WSTRING, wsData AS WSTRING) AS WSTRING
                DIM pHttpReq AS IWinHttpRequest
                pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
                pHttpReq.Open "POST", wsURL, 0
                pHttpReq.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                pHttpReq.Send(wsData)
             END FUNCTION
            '

            .
            .

            Comment


            • #86
              Stuart, in the above functions where are you getting the response?
              I assume you wanted to reuse wsData both to pass the request, and get the response.
              you have no wsData = pHttpReq.ResponseText

              Gary I strongly recommend you use the version with error checking. In a recent thread Mike was having an Issue with TLS version, and the error checking steered me in the wright direction to locate cause.

              Just copy the function into your "myInternetStuff.inc" or make it into an SLL, Forget about it, and then you have a one-liner you love so much.


              wsdata="param1=rabbit" :PostData("http://myserver.com/lookup.php", wsData) : ? wsdata

              Comment


              • #87
                WinhttpGet can be a 1-liner as far as calling and displaying results or exiting on error.
                It works with protected pages and cgi programs to send a request and return a file or request as a string.
                Code:
                #INCLUDE "httprequest.inc" 'WinHttpGet.bas
                #INCLUDE "ole2utils.inc"
                
                FUNCTION PBMAIN()
                 IF ISFALSE(WinHttpGet("https://dotysoftware.com/test.txt","","","",sData$,sError$)) THEN ? sData$,,sError$
                END FUNCTION
                
                FUNCTION WinHttpGet(sURL AS STRING,_
                          sUserName      AS STRING,_
                          sPassword      AS STRING,_
                          sRequest       AS STRING,_
                          sDataReturned  AS STRING,_
                          sError         AS STRING) AS LONG
                'https://forum.powerbasic.com/forum/jose-s-corner/source-code-ab/51694-winhhtp-com-examples
                'https://www.808.dk/?code-simplewinhttprequest
                 LOCAL pHttpReq AS IWinHttpRequest
                 pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
                 IF ISNOTHING(pHttpReq) THEN ? "WinHttpRequest.5.1 failure",%MB_ICONERROR OR %MB_SYSTEMMODAL,FUNCNAME$:EXIT FUNCTION
                 TRY
                  pHttpReq.Open "GET", sURL + sRequest, 0
                  IF LEN(sUserName)AND LEN(sPassword) THEN
                    pHttpReq.SetCredentials sUserName,sPassword,%HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
                  END IF
                  pHttpReq.Send
                  IF pHttpReq.StatusText <> "OK" THEN
                   sError = pHttpReq.StatusText
                   FUNCTION = 1
                  ELSE
                   sDataReturned = pHttpReq.ResponseText
                   sError = pHttpReq.StatusText
                  END IF
                 CATCH
                  OleShowErrorInfo OBJRESULT
                  FUNCTION = 1
                 END TRY
                 SET phttpReq = NOTHING
                END FUNCTION

                Comment


                • #88
                  Originally posted by Rod Macia View Post
                  Stuart, in the above functions where are you getting the response?
                  I'm not. This was for Gray's "For the case of a PHP that doesn't return anything (just takes an action on the server and closes"
                  The only "response" is the returned HTTP StatusText.

                  Try using that function to this one line PHP file: Hopefully your data is appended to logfile.txt and you get an "OK" messagebox
                  Code:
                  <?php file_put_contents('logfile.txt',file_get_contents('php://input')."\r\n",FILE_APPEND); ?>
                  Or if you're not interested in error trapping and a response, try this minimalist code with that one line PHP file
                  '
                  Code:
                  #INCLUDE "httprequest.inc"
                  FUNCTION PBMAIN() AS LONG
                      Postdata("http://test.test/argTest4.php",DATE$ & " " & TIME$ & ": " & "Some data for the log file")
                  END FUNCTION
                  
                  FUNCTION PostData(wsURL AS WSTRING, wsData AS WSTRING) AS WSTRING
                      DIM pHttpReq AS IWinHttpRequest
                      pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
                      pHttpReq.Open "POST", wsURL, 0
                      pHttpReq.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                      pHttpReq.Send(wsData)
                   END FUNCTION
                  '
                  Last edited by Stuart McLachlan; 25 Sep 2022, 02:03 AM.

                  Comment


                  • #89
                    Originally posted by Stuart McLachlan View Post
                    I'm not. This was for Gray's "For the case of a PHP that doesn't return anything (just takes an action on the server and closes"
                    The only "response" is the returned HTTP StatusText.
                    I know you are responding to Gary's minimalistic views.
                    Fundamentally that would be ill-advised, the Post request can succeed at the HTTP level, which would generate a positive "response" in the returned HTTP StatusText, but the PHP may fail to complete as expected, an you would not know about it. The PHP should return some sort of OK/NOT OK message.

                    Comment


                    • #90
                      Reviewing some code, I just noticed that I had copied a pointless test from this post:

                      Originally posted by Mike Doty View Post
                      ...
                      FUNCTION GetOrPost(GetMethod AS LONG ,_
                      ...
                      IF GetMethod THEN
                      pHttpReq.Open "GET", wsURL + wsRequest, 0
                      ELSE
                      pHttpReq.Open "POST", wsURL + wsRequest, 0
                      END IF
                      ...
                      iSucceeded = pHttpReq.WaitForResponse(5) 'added 9/22/22
                      ...
                      https://learn.microsoft.com/en-us/wi...tprequest-open
                      Async [in, optional]
                      Indicates whether to open in asynchronous mode.
                      Value Meaning
                      VARIANT_FALSE Opens the HTTP connection in synchronous mode. A call to Send does not return until WinHTTP has completely received the response.
                      VARIANT_TRUE Opens the HTTP connection in asynchronous mode.


                      https://learn.microsoft.com/en-us/wi...aitforresponse
                      The WaitForResponse method waits for an asynchronous Send method to complete, with optional time-out value, in seconds.
                      Calling this property after a synchronous Send method returns immediately and has no effect.​


                      IOW, since the connection is being opened with "0", (i.e. False = synchronous), the WaitforResponse in this code does nothing.

                      Comment


                      • #91
                        Originally posted by Rod Macia View Post
                        I know you are responding to Gary's minimalistic views.
                        Fundamentally that would be ill-advised, the Post request can succeed at the HTTP level, which would generate a positive "response" in the returned HTTP StatusText, but the PHP may fail to complete as expected, an you would not know about it. The PHP should return some sort of OK/NOT OK message.
                        I agree 100% with your philosophy.
                        I'd never actually do something like that in production code, but he did ask

                        Comment


                        • #92
                          http://www.garybeene.com/power/code/gbsnippets0052.htm

                          WinhttpGet "http://www.garybeene.com/power/code/gbsnippets0052.htm","","","",sdata,sError​

                          This is the CATCH of the TRY statement. OleShowErrorInfo OBJRESULT
                          This error message box displays without OleShowErrorInfo OBJRESULT
                          Is there a way to suppress this message box and get the data from the above link?

                          If the function can download an .exe file, why does it choke on a .htm file?
                          Is there some setting to allow any file extension without error checking for characters?


                          Click image for larger version  Name:	image.png Views:	0 Size:	15.4 KB ID:	819065




                          Comment


                          • #93
                            I don't know if you can suppress the error message, but you can use pWHttp.ResponseBody instead of pWHttp.Responsetext

                            '
                            Code:
                            #COMPILE EXE    'Jose Roca Includes
                            #DIM ALL
                            #UNIQUE VAR ON
                            
                            %Unicode = 1
                            FUNCTION PBMAIN () AS LONG
                            LOCAL sBuffer AS WSTRING
                                    sBuffer = GetHTTPsfromWEB("http://www.garybeene.com/power/code/gbsnippets0052.htm")
                                    CLIPBOARD SET TEXT sBuffer
                                    ? sBuffer
                            END FUNCTION
                            
                            #INCLUDE ONCE "httprequest.inc"
                            #INCLUDE ONCE "ole2utils.inc"
                            '-----------------------------------------------
                            FUNCTION GetHTTPsfromWEB (sFullURL AS STRING) AS WSTRING
                            '-----------------------------------------------
                            ' GetHTTPsfromWEB
                            ' Opens an HTTP or HTTPS connection to an HTTP resource
                            ' Usage     GetHTTPsfromWEB (sFullURL)
                            ' Usage     GetHTTPsfromWEB ("https:/www.mydomain.com/whatever.html)
                               LOCAL pWHttp AS IWinHttpRequest
                               LOCAL buffer AS STRING
                               LOCAL vBody AS VARIANT
                               LOCAL nBytes AS LONG
                               LOCAL iSucceeded AS INTEGER
                               DIM   vByteArray(0) AS BYTE
                            
                               ' Creates an instance of the HTTP service
                               pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
                            
                               IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
                               TRY
                                  ' Opens an HTTP or HTTPS connection to an HTTP resource
                                  pWHttp.Open "GET", sFullURL
                                  ' Sends an HTTP request to the HTTP server
                                  pWHttp.Send
                                  ' Wait for response with a timeout of 5 seconds
                                  iSucceeded = pWHttp.WaitForResponse(5)
                                    ' buffer = pWHttp.Responsetext
                                     vBody = pWHttp.ResponseBody
                                      ' Convert the variant to an array of bytes
                                      vByteArray() = vBody
                                      ' Convert the array of bytes to a string
                                      nBytes = UBOUND(vByteArray) - LBOUND(vByteArray) + 1
                                      IF nBytes THEN
                                         buffer = PEEK$(VARPTR(vByteArray(0)), nBytes)
                                      END IF
                               CATCH
                                  OleShowErrorInfo OBJRESULT
                               END TRY
                            FUNCTION = buffer
                            END FUNCTION
                            '-----------------------------------------------
                            ' GetHTTPsfromWEB                            End
                            '-----------------------------------------------
                            '

                            Comment


                            • #94
                              Great!!, Rod.
                              1. Could not get clipboard to correctly display so writes to disk and shellexecute

                              2. Added returning error code
                              sStatus = pWHttp.StatusText
                              IF sStatus <> "OK" THEN EXIT TRY​

                              3. Not sure if CATCH will ever fire (not a bad thing!)
                              Code:
                              #COMPILE EXE "gary2"  'Jose Roca Includes
                              #DIM ALL
                              #UNIQUE VAR ON
                              #INCLUDE ONCE "httprequest.inc"
                              #INCLUDE ONCE "ole2utils.inc"
                              %Unicode = 1
                              %ShellOut = 1  'new window opened with each file
                              MACRO mFormat(value,length) = RSET$(FORMAT$(value),length USING "0")
                              
                              FUNCTION PBMAIN () AS LONG
                               MKDIR "c:\gary2"
                               CHDIR "c:\gary2"
                               LOCAL sUrl,sBuffer ,sFileName,snum,sStatus AS STRING
                               LOCAL x AS LONG
                                x = 52
                                snum = mFormat(x,4)
                                sUrl = "http://www.garybeene.com/power/code/gbsnippets" + snum + ".htm"
                                sBuffer = GetHTTPsfromWEB(sUrl,sStatus)
                                IF sStatus = "OK" THEN
                                 sFileName = snum + ".htm"
                                 OPEN sFileName FOR OUTPUT AS #1
                                 PRINT #1,sBuffer;
                                 CLOSE #1
                                 IF %ShellOut THEN  ShellExecute (%NULL, "OPEN", sFileName + $NUL, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
                                ELSE
                                 ? sStatus,%MB_ICONERROR,"Error"
                                END IF
                                ? "Done",%MB_SYSTEMMODAL
                              END FUNCTION
                              '-----------------------------------------------
                              FUNCTION GetHTTPsfromWEB (sFullURL AS STRING,sStatus AS STRING) AS WSTRING
                              '-----------------------------------------------
                              ' GetHTTPsfromWEB
                              ' Opens an HTTP or HTTPS connection to an HTTP resource
                              ' Usage     GetHTTPsfromWEB (sFullURL)
                              ' Usage     GetHTTPsfromWEB ("https:/www.mydomain.com/whatever.html)
                                 LOCAL pWHttp AS IWinHttpRequest
                                 LOCAL buffer AS STRING
                                 LOCAL vBody AS VARIANT
                                 LOCAL nBytes AS LONG
                                 LOCAL iSucceeded AS INTEGER
                                 DIM   vByteArray(0) AS BYTE
                              
                                 ' Creates an instance of the HTTP service
                                 pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
                              
                                 IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
                                 TRY
                                    ' Opens an HTTP or HTTPS connection to an HTTP resource
                                    pWHttp.Open "GET", sFullURL
                                    ' Sends an HTTP request to the HTTP server
                                    pWHttp.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                                    pWHttp.Send
                                    ' Wait for response with a timeout of 5 seconds
                                      iSucceeded = pWHttp.WaitForResponse(5) 'always returns -1
                                      ' buffer = pWHttp.Responsetext
                                       vBody = pWHttp.ResponseBody
                                       sStatus = pWHttp.StatusText
                                       IF sStatus <> "OK" THEN EXIT TRY
                                       ' Convert the variant to an array of bytes
                                        vByteArray() = vBody
                                        ' Convert the array of bytes to a string
                                        nBytes = UBOUND(vByteArray) - LBOUND(vByteArray) + 1
                                        IF nBytes THEN
                                           buffer = PEEK$(VARPTR(vByteArray(0)), nBytes)
                                        END IF
                                 CATCH
                                  ? "Never executes"
                                  OleShowErrorInfo OBJRESULT
                                 END TRY
                              FUNCTION = buffer
                              END FUNCTION
                              '-----------------------------------------------
                              ' GetHTTPsfromWEB                            End
                              '-----------------------------------------------

                              Comment


                              • #95
                                Originally posted by Mike Doty View Post
                                http://www.garybeene.com/power/code/gbsnippets0052.htm

                                WinhttpGet "http://www.garybeene.com/power/code/gbsnippets0052.htm","","","",sdata,sError​

                                This is the CATCH of the TRY statement. OleShowErrorInfo OBJRESULT
                                This error message box displays without OleShowErrorInfo OBJRESULT
                                I think you are mistaken.
                                Comment out that line and you don't get it.
                                Incidentally, there is no need for # INCLUDE "ole2utils.inc" and OleSHowErrorInfo with current PBs.
                                Just remove the #I INCLUDE and replace the line with ? OBJRESULT$() or $ str$(OBJRESULT) & " : : & OBJRESULT$) and you will get a simpler message

                                Click image for larger version  Name:	OBJResult.jpg Views:	0 Size:	43.9 KB ID:	819072

                                Is there a way to suppress this message box and get the data from the above link?
                                Suppress? - yes, see above.
                                Get the data? - The problem is the page content. Even FF can't display the weird characters byte codes that are embedded in it. They are not valid UTF (either 8 or 16) !

                                Click image for larger version  Name:	Badchars.jpg Views:	0 Size:	101.8 KB ID:	819073


                                The error is occuring when pHttpReq.ResponseText is trying to make sense of those bytes.

                                If the function can download an .exe file, why does it choke on a .htm file?
                                Is there some setting to allow any file extension without error checking for characters?​
                                Not as long as the server is saying that it is HTML text encoded as UTF8

                                Click image for larger version  Name:	contenttype.jpg Views:	12 Size:	42.8 KB ID:	819074
                                Last edited by Stuart McLachlan; 25 Sep 2022, 09:34 PM.

                                Comment


                                • #96
                                  Originally posted by Mike Doty View Post
                                  Great!!, Rod.
                                  1. Could not get clipboard to correctly display so writes to disk and shellexecute
                                  Clipboard won't display correctly because of the invalid UTF codes
                                  We've fortunate that modern browsers are very forgiving when they try to display what is returned by the server

                                  Comment


                                  • #97
                                    Gary's page contains &HA0 characters = CHR$ (160) = ANSI "Nobreak Space". It is not a valid UTF value- that's what is messing up to saving to ResponseText and the display when the server says that it is delivering UTF text.

                                    As a general rule, you should NOT include such characters ini a web page. If you do, you need to put a "<meta charset= Windows-1252>" or similar in the headers
                                    I'm not suprised that people have problems with some of Gary's pages. The one in question is very deficient All it contains is:
                                    Code:
                                    <html><body>​
                                    ...
                                    ​which goes against just about every rule of structuring an HTML page.

                                    When it is saved using Mikes Post 94 and opened in a browser with ShellExecute, the browser doesn't know what form it is in but interprets it as ANSI text and so displays the non breaking spaces. Unfortunately his web server doesn't second guess his content, assumes that he has done the right thing and declares it as the default Content-Type text/html; charset=UTF-8.

                                    Comment


                                    • #98
                                      Rod and Stuart,
                                      Setting credentials when not needed is even correctly handled without an unsightly message box or crash.
                                      Replace all AS STRING with AS WSTRING. It works either way.
                                      Code:
                                      #COMPILE EXE   'Jose Roca Includes
                                      #INCLUDE "windows.inc"
                                      #INCLUDE ONCE "httprequest.inc"
                                      'MACRO mFormat(value,length) = RSET$(FORMAT$(value),length USING "0")
                                      
                                      FUNCTION PBMAIN () AS LONG
                                       LOCAL sURL,sBuffer,sError,sUserName,sPassword AS STRING
                                       sURL = "http://www.garybeene.com/power/code/gbsnippets0054.htm"
                                       sUserName = ""
                                       sPassword = ""
                                       sBuffer = GetHTTPsfromWEB(sUrl,sError,sUserName,sPassword)
                                       ? USING$("&&#, bytes returned",sURL,$CRLF,LEN(sBuffer)),,sError
                                      END FUNCTION
                                      
                                      FUNCTION GetHTTPsfromWEB _
                                                (sFullURL  AS STRING, _
                                                 sError    AS STRING, _
                                                 sUserName AS STRING,_
                                                 sPassword AS STRING) AS STRING
                                       RESET sError
                                      ' GetHTTPsfromWEB
                                      ' Opens an HTTP or HTTPS connection to an HTTP resource
                                      ' Usage     GetHTTPsfromWEB (sFullURL)
                                      ' Usage     GetHTTPsfromWEB ("https:/www.mydomain.com/whatever.html)
                                       LOCAL pWHttp      AS IWinHttpRequest
                                       LOCAL sbuffer     AS STRING
                                       LOCAL vBody       AS VARIANT
                                       LOCAL nBytes      AS LONG
                                       LOCAL iSucceeded  AS INTEGER
                                       DIM vByteArray(0) AS BYTE
                                      
                                       ' Creates an instance of the HTTP service
                                       pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
                                      
                                       IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
                                       TRY
                                        ' Opens an HTTP or HTTPS connection to an HTTP resource
                                        pWHttp.Open "GET", sFullURL
                                        IF LEN(sUserName)AND LEN(sPassword) THEN
                                         pWHttp.SetCredentials sUserName,sPassword,%HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
                                        END IF
                                        ' Sends an HTTP request to the HTTP server
                                        pWHttp.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                                        pWHttp.Send
                                        ' Wait for response with a timeout of 5 seconds
                                        iSucceeded = pWHttp.WaitForResponse(5) 'always returns -1
                                      
                                        vBody = pWHttp.ResponseBody 'Stuart
                                        sError = pWHttp.StatusText
                                        IF sError <> "OK" THEN EXIT TRY
                                        ' Convert the variant to an array of bytes
                                        vByteArray() = vBody
                                        ' Convert the array of bytes to a string
                                        nBytes = UBOUND(vByteArray) - LBOUND(vByteArray) + 1
                                        IF nBytes THEN sbuffer = PEEK$(VARPTR(vByteArray(0)), nBytes)
                                        CATCH
                                         sError = OBJRESULT$ 'parameters invalid ...
                                        END TRY
                                      FUNCTION = sbuffer
                                      END FUNCTION

                                      Comment


                                      • #99
                                        Originally posted by Mike Doty View Post
                                        Code:
                                        vBody = pWHttp.ResponseBody
                                        sError = pWHttp.StatusText
                                        IF sError <> "OK" THEN EXIT TRY
                                        ' Convert the variant to an array of bytes
                                        vByteArray() = vBody
                                        ' Convert the array of bytes to a string
                                        nBytes = UBOUND(vByteArray) - LBOUND(vByteArray) + 1
                                        IF nBytes THEN sbuffer = PEEK$(VARPTR(vByteArray(0)), nBytes)
                                        That will not work if a the site is encoded/transmitted as UTF8 with values > 127 or as UTF16.
                                        It works with Gary's pages because his are plain single byte ANSI text. In a UTF8 page, his CHR$(160) would be encoded as &HC2A0​, not just &HA0. In a UTF16 page, it would be &H00A0

                                        Comment


                                        • That will not work if the the site is UTF8 encoded with values > 127 or if it is UTF16 encoded.
                                          The whole thing won't work or not using WSTRING?

                                          Comment

                                          Working...
                                          X