Author Topic: Just test if a download would work?  (Read 4643 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 929
  • User-Rate: +30/-4
    • it-berater
Just test if a download would work?
« on: September 16, 2013, 08:43:33 PM »
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?

Offline Chris Holbrook

  • Newbie
  • *
  • Posts: 44
  • User-Rate: +5/-2
Re: Just test if a download would work?
« Reply #1 on: September 16, 2013, 09:11:32 PM »
Does the HEAD method help? If you look at the XHR documentation, you have GET, POST, HEAD and some small change.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 929
  • User-Rate: +30/-4
    • it-berater
Re: Just test if a download would work?
« Reply #2 on: September 16, 2013, 09:25:35 PM »
Ok, that was a good idea, now i found some links as a starting point.

Download with Progress

Download to String

and for me less interesting:

FTP GetFile

httpGet  DL-SpeedTest

Maybe something like this?
If U03=0 it should download all of the file otherwise just the first 4096 Bytes.

Code: [Select]
'######################################################################################################################
'######################################################################################################################
'  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   
« Last Edit: September 16, 2013, 10:13:00 PM by Theo Gottwald »