We have some code sort of "WEBGET" to download a file.
What if i do not want to download the file, but just check if the download link is valid?
Has anybody some code/idea for that?
Does the HEAD method help? If you look at the XHR documentation, you have GET, POST, HEAD and some small change.
Ok, that was a good idea, now i found some links as a starting point.
Download with Progress (http://www.powerbasic.com/support/pbforums/showthread.php?t=50193&highlight=download)
Download to String (http://www.powerbasic.com/support/pbforums/showthread.php?t=45463&highlight=download)
and for me less interesting:
FTP GetFile (http://www.powerbasic.com/support/pbforums/showthread.php?t=44460&highlight=download)
httpGet DL-SpeedTest (http://www.powerbasic.com/support/pbforums/showthread.php?t=43726&highlight=download)
Maybe something like this?
If U03=0 it should download all of the file otherwise just the first 4096 Bytes.
'######################################################################################################################
'######################################################################################################################
' site = "www.nbson.com"
' file = "/speedData/httpTest.html"
FUNCTION httpGet(BYVAL U01 AS STRING,OPT BYVAL U03 AS BYTE) AS LONG
LOCAL buffer AS STRING
LOCAL temp AS STRING
LOCAL fNumber AS LONG
LOCAL T01,T02,T03 AS LONG
LOCAL file,site AS STRING
U01=LCASE$(TRIM$(U01))
T02=INSTR(U01,"//")
IF zero(T02) THEN T03=1 ELSE T03=T02+2
T02=INSTR(T03,U01,"/")
IF zero(T02) THEN GOTO enx
Site=MID$(U01,1 TO T02-1)
file=MID$(U01,T02)
fNumber=FREEFILE
TCP OPEN PORT 80 AT site AS #fNumber TIMEOUT 10000
IF ERR THEN
FUNCTION= -1
EXIT FUNCTION
END IF
TCP PRINT #fNumber, "GET " & file & " HTTP/1.1"
TCP PRINT #fNumber, "Accept: */*"
TCP PRINT #fNumber, "Accept-Language: en-us"
TCP PRINT #fNumber, "Host: " & site
TCP PRINT #fNumber, "Pragma: no-cache"
TCP PRINT #fNumber, "Referer: http://"+site+"/"
TCP PRINT #fNumber, "UserAgent: webget 1.2 ("+ site +")"
TCP PRINT #fNumber, ""
DO
TCP RECV #fNumber, 4096, buffer
temp = temp & buffer
IF U03=1 THEN T01=1: EXIT LOOP
IF ERR THEN T01=0:EXIT LOOP
LOOP WHILE LEN(buffer)
' ** close the tcp connection
TCP CLOSE #fNumber
enx:
FUNCTION=T01
EXIT FUNCTION
END FUNCTION