curl_download¶
curl_download lädt eine Datei per HTTP, HTTPS, FTP, SFTP und weiteren Protokollen aus dem Internet.
-
data = curl_download(ssURL)
-
data = curl_download(ssURL, oOptions)
Returnwert
Im Fehlerfall wird ein error-Objekt (siehe error_create) zurück gegeben, sonst ein Objekt mit den Daten.
In data.cnt
steht die Anzahl an Datenblöcken.
data[1]
bis data[cnt]
enthalten die Daten als Strings in gepackter
Form, das heißt in jedem Zeichen stehen 2 Bytes. Im letzten Zeichen stehen ein
oder zwei Bytes. Die Bytes können 0-Zeichen enthalten. Siehe mem_len und
mem_unpack.
Der folgende Code konvertiert data in einen String:
s = "";
if (data.cnt != 0) {
for (i in 1:data.cnt) {
s = s + mem_unpack(data.data[i]);
}
s = utf8_decode(s);
}
Parameter
-
ssURL
ssURL ist die URL.
-
oOptions
oOptions ist ein Objekt mit Optionen oder 0, siehe curl_easy_setopt.
Beispiel
Der folgende Aufruf liest eine Text-Datei aus dem Internet:
def curl_download_text(ssURL, _oOptions)
{
nArgs = nargsin();
if (nArgs == 1) {
o = curl_download(ssURL)
} else if (nArgs == 2) {
o = curl_download(ssURL, _oOptions);
} else {
error();
}
if (type(o) == "error") {
return o;
}
s = "";
if (o.cnt == 0) {
return s;
}
for (i in 1:o.cnt) {
s = s + mem_unpack(o.data[i]);
}
return utf8_decode(s);
}
s = curl_download_text("www.uniplot.de")
Den Download in einer Datei speichern:
ssBinary = curl_download_binary(ssURL, _oOptions)
ssOK = curl_download_binary(ssURL, _oOptions, ssSaveFileName)
Beispiel:
if (curl_download_binary("https://www.uniplot.de/_images/monitor.png", 0, "d:/a.png") == "OK") {
print "success";
}
History
Version | Beschreibung |
---|---|
R2015.0 | Neu. |
Siehe auch
id-930757