.. highlightlang:: us .. index:: curl_download .. _curl_download: curl_download ============= .. us.tag curl_download GERMAN Curl New5700 :ref:`curl_download` lädt eine Datei per HTTP, HTTPS, FTP, SFTP und weiteren Protokollen aus dem Internet. .. function:: data = curl_download(ssURL) data = curl_download(ssURL, oOptions) .. us.return **Returnwert** Im Fehlerfall wird ein *error*-Objekt (siehe :ref:`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 :ref:`mem_len` und :ref:`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); } .. us.params **Parameter** .. uparam:: ssURL *ssURL* ist die URL. .. uparam:: oOptions *oOptions* ist ein Objekt mit Optionen oder 0, siehe :ref:`curl_easy_setopt`. .. us.example **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: .. index:: curl_download_binary :: 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"; } .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Beschreibung * - R2015.0 - Neu. .. seealso:: :ref:`overview-curl`, :ref:`curl_easy_setopt`, :ref:`mem_len`, :ref:`mem_unpack` :sub:`id-930757`