server$ = "ws.correios.com.br"
query$ = "/calculador/CalcPrecoPrazo.asmx/CalcPrazo?nCdServico=10154&sCepOrigem=69910000&sCepDestino=99920000"
PRINT "Attempting to fetch data..."
IF Download
(server$
+ query$
, "correios.xml", 10) THEN ' timelimit = 10 seconds
FUNCTION Download
(url$
, file$
, timelimit
) ' returns -1 if successful, 0 if not url2$ = url$
e$
= CHR$(13) + CHR$(10) ' end of line characters x$ = "GET " + url3$ + " HTTP/1.1" + e$
x$ = x$ + "Host: " + url2$ + e$ + e$
_DELAY 0.05 ' 50ms delay (20 checks per second) a$ = a$ + a2$
i
= INSTR(a$
, "Content-Length:") l
= VAL(MID$(a$
, i
+ 15, i2
- i
- 14)) i3
= INSTR(i2
, a$
, e$
+ e$
) i3 = i3 + 4 'move i3 to start of data
CLOSE client
' CLOSE CLIENT Download = -1 'indicates download was successfull
END IF ' availabledata = l