curl_easy_initΒΆ
curl_easy_init creates a curl pointer. The pointer can be destroyed with curl_easy_cleanup.
- curl = curl_easy_init()
Return Value
curl is the curl pointer.
Comment
The curl functions use the cURL library, see http://curl.haxx.se/.
Example
Example 1: Download utf8 text file.
curl_download_text("http://www.uniplot.de")
def _DownloadCBData(data, user)
{
user.cnt = user.cnt + 1;
user.data[user.cnt] = data;
return 1;
}
def curl_download_text(ssURL)
{
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, ssURL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, "_DownloadCBData");
o = [. cnt = 0, data = [.]];
curl_easy_setopt(curl, CURLOPT_WRITEDATA, o);
r = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (r != 0) {
return error_create("CURL", r, curl_easy_strerror(r));
}
s = "";
if (o.cnt == 0) {
return s;
}
for (i in 1:o.cnt) {
s = s + mem_unpack(o.data[i]);
}
return utf8_decode(s);
}
Example 2: Upload using FTP protocoll:
def _curl_upload_callback(nBytes, oUser)
{
return fread_char8(oUser.fp, nBytes);
}
def curl_upload_test(ssFile, ssURL, oOptions)
{
ssFilename = sum(SplitPath(ssFile)[3:4]);
_ssURL = ssURL + ssFilename;
curl = curl_easy_init();
curl_easy_setopt(curl, oOptions);
curl_easy_setopt(curl, CURLOPT_URL, _ssURL);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, "_curl_upload_callback");
fp = fopen(ssFile, "rb");
if (fp == 0) {
return error_create("file", 1, "Cannot open file");;
}
oUser = [. fp = fp];
curl_easy_setopt(curl, CURLOPT_READDATA, oUser);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
/* Set the size of the file to upload */
n = fgetlen(fp);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, n);
r = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
if (r != 0) {
return error_create("CURL", r, curl_easy_strerror(r));
}
return 0;
}
curl_upload_test("d:\\test.txt", "ftp://www.example.com/", [. username = "Peter", password = "Geheim", timeout=5])
History
Version |
Description |
---|---|
R2015.0 |
New. |
See also
id-1511818