Originally posted by Stuart McLachlan
View Post
or you created a new php
wsrequest = "select rowid from parts where rowid % 1000 = 0 order by rowid;"
<?php $data = file_get_contents('php://input'); echo $data; ?>
<?php $data = file_get_contents('php://input'); echo $data; ?>
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 '
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 '
#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
<?php file_put_contents('logfile.txt',file_get_contents('php://input')."\r\n",FILE_APPEND); ?>
#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 '
#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 '----------------------------------------------- '
#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 '-----------------------------------------------
<html><body> ...
#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
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)
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment