' SED_PBCC
'----------------------------------------------------------------------------(')
#INCLUDE "win32api.inc"
'----------------------------------------------------------------------------(')
%INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry configuration
%INTERNET_FLAG_PRAGMA_NOCACHE = &H00000100 ' asking wininet to add "pragma: no-cache"
%INTERNET_FLAG_NEED_FILE = &H00000010 ' need a file for this request
%INTERNET_FLAG_NO_CACHE_WRITE = &H04000000 ' don't write this item to the cache
%INTERNET_FLAG_FROM_CACHE = &H01000000 ' use offline semantics
%INTERNET_FLAG_RELOAD = &H80000000 ' retrieve the original item
%http_blocksize = 4096
'----------------------------------------------------------------------------(')
DECLARE FUNCTION INTERNETOPEN LIB "wininet.dll" ALIAS "InternetOpenA" _
( _
lpszAgent AS ASCIIZ, _ ' in
BYVAL dwAccessType AS DWORD, _ ' in
lpszProxy AS ASCIIZ, _ ' in
lpszProxyBypass AS ASCIIZ, _ ' in
BYVAL dwFlags AS DWORD _ ' in
) _
AS DWORD
DECLARE FUNCTION INTERNETOPENURL LIB "wininet.dll" ALIAS "InternetOpenUrlA" _
( _
BYVAL hInternet AS DWORD, _ ' in
lpszUrl AS ASCIIZ, _ ' in
lpszHeaders AS ASCIIZ, _ ' in
BYVAL dwHeadersLength AS DWORD, _ ' in
BYVAL dwFlags AS DWORD, _ ' in
BYVAL dwContext AS DWORD _ ' in
) _
AS DWORD
DECLARE FUNCTION INTERNETREADFILE LIB "wininet.dll" ALIAS "InternetReadFile" _
( _
BYVAL hFile AS DWORD, _ ' in
BYVAL lpBuffer AS BYTE PTR, _ ' in
BYVAL dwNumberOfBytesToRead AS DWORD, _ ' in
lpdwNumberOfBytesRead AS DWORD _ ' out
) _
AS LONG
DECLARE FUNCTION INTERNETCLOSEHANDLE LIB "wininet.dll" _
ALIAS "InternetCloseHandle" _
( _
BYVAL hInternet AS DWORD _ ' in
) _
AS LONG
'----------------------------------------------------------------------------(')
FUNCTION PBMAIN AS LONG
'
LOCAL TS1 AS STRING
LOCAL URL AS STRING
'
URL = "http://www.powerbasic.com"
STDOUT "Content-type: text/html"
STDOUT
STDOUT "<table bgcolor=""white""><tr><td><hr> Page Downloaded Via Cgi Script : " + URL + "<hr><br /><br /></tr></td></table>"
'
CALL urldownloadtostring( URL, TS1 )
'
STDOUT TS1;
'
END FUNCTION
'----------------------------------------------------------------------------(')
FUNCTION urldownloadtostring( szurl AS STRING, szbuf AS STRING ) AS LONG
'
DIM bytesread AS LOCAL LONG
DIM er AS LOCAL LONG
DIM hfile AS LOCAL LONG
DIM hinternetsession AS LOCAL DWORD
DIM lbuf AS LOCAL LONG
DIM sztmp AS LOCAL STRING
DIM sztmpbuf AS LOCAL STRING
'
DO
'
hinternetsession = INTERNETOPEN( "pb/dll 7.04", %INTERNET_OPEN_TYPE_PRECONFIG, BYVAL 0, BYVAL 0, 0 )
'
IF hinternetsession = 0 THEN
er = - 1
EXIT DO
END IF
'
sztmp = "pragma: no-cache"
'
hfile = INTERNETOPENURL( hinternetsession, BYVAL STRPTR( szurl ), _
BYVAL STRPTR( sztmp ), BYVAL LEN( sztmp ), %INTERNET_FLAG_PRAGMA_NOCACHE OR _
%INTERNET_FLAG_NO_CACHE_WRITE OR %INTERNET_FLAG_RELOAD, 0 )
'
IF hfile = 0 THEN
er = - 1
EXIT DO
END IF
'
szbuf = SPACE$( %http_blocksize )
'
DO
'
IF INTERNETREADFILE( hfile, BYVAL STRPTR( szbuf ), %http_blocksize, BYREF lbuf ) = 0 THEN
er = - 1
EXIT DO
END IF
'
IF lbuf = 0 THEN
EXIT DO
END IF
'
IF LEN( sztmpbuf ) <( lbuf + bytesread ) THEN
'
IF LEN( sztmpbuf ) = 0 THEN
sztmpbuf = SPACE$( &h100000 )
ELSE
sztmpbuf = sztmpbuf + sztmpbuf
END IF
'
END IF
'
MID$( sztmpbuf, bytesread + 1, lbuf ) = LEFT$( szbuf, lbuf )
'
bytesread = bytesread + lbuf
'
LOOP
'
EXIT DO
'
LOOP
'
IF hfile THEN
INTERNETCLOSEHANDLE hfile
end if
'
IF hinternetsession THEN
INTERNETCLOSEHANDLE hinternetsession
end if
'
IF er THEN
FUNCTION = er
bytesread = 0
end if
'
szbuf = LEFT$( sztmpbuf, bytesread )
'
END FUNCTION