5. Juli 2021 10:53
wget(_URI : Text[1024];_filename : Text[1024]) : Boolean
//_URI := https://irgendeinewebsite.de <-- diese soll komplett heruntergeladen werden um sie anschließend in einer Textdatei zu speichern, WGET simuliert dies
//Name DataType Subtype Length
//xmlHTTP Automation 'Microsoft XML, v6.0'.XMLHTTP60
//locautXmlDoc Automation 'Microsoft XML, v6.0'.DOMDocument60
IF (_URI = '') OR (_filename = '') THEN
EXIT(FALSE);
IF EXISTS(_filename) THEN
ERASE(_filename);
IF ISCLEAR(xmlHTTP) THEN
CREATE(xmlHTTP);
xmlHTTP.open('GET',_URI,FALSE);
xmlHTTP.send();
TimeBegin := TIME;
REPEAT
TimeElapsed := TIME - TimeBegin;
readyState := xmlHTTP.readyState;
IF readyState > 0 THEN BEGIN
statusCode := xmlHTTP.status;
statusText := xmlHTTP.statusText;
END;
UNTIL (readyState = 4) OR ((((TimeElapsed/1000)/60)/60) > 12); // 12 hour limit
IF (xmlHTTP.status = 200) AND (xmlHTTP.statusText = 'OK') THEN BEGIN
savefile(_filename);
exit(true);
END ELSE BEGIN
EXIT(FALSE);
END;
----------------------------------------------
savefile(_filename : Text[1024])
//speichern den HTTPREsonse als Datei
_var := xmlHTTP.responseStream;
_is := _var;
_bigText.READ(_is);
ToFile.CREATE(_filename);
ToFile.TEXTMODE(TRUE);
ToFile.CREATEOUTSTREAM(_os);
_bigText.WRITE(_os);
ToFile.CLOSE;