curl_downloadΒΆ

curl_download loads data from the Internet, using HTTP, HTTPS, FTP, SFTP and other protocols.

data = curl_download(ssURL)
data = curl_download(ssURL, oOptions)

Return Value

In case of an error, an error object (see error_create) is returned, otherwise an object with data is returned..

The number of data blocks is returned in data.cnt.

data[1] to data[cnt] contains the data blocks as strings in a packed form. Each character is two bytes long. The last character contains one or two bytes. The bytes can contain zero bytes. See mem_len and mem_unpack.

Convert data to an string:

s = "";
if (data.cnt != 0) {
    for (i in 1:data.cnt) {
        s = s + mem_unpack(data.data[i]);
    }
    s = utf8_decode(s);
}

Parameters

ssURL

ssURL is the URL.

oOptions

oOptions is an object with options or 0, see curl_easy_setopt.

Example

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")

Save the download in a file:

ssBinary = curl_download_binary(ssURL, _oOptions)
ssOK = curl_download_binary(ssURL, _oOptions, ssSaveFileName)

Example:

if (curl_download_binary("https://www.uniplot.de/_images/monitor.png", 0, "d:/a.png") == "OK") {
   print "success";
}

History

Version Description
R2015.0 New.

id-930757