Dropbox API 在C ++中通过curl下载文件
示例
#include <stdio.h> #include <curl/curl.h> int main (int argc, char *argv[]) { CURL *curl; CURLcode res; /* In windows, this will init the winsock stuff */ curl_global_init(CURL_GLOBAL_ALL); /* get a curl handle */ curl = curl_easy_init(); if(curl) { printf ("Running curl test.\n"); struct curl_slist *headers=NULL; /* init to NULL is important */ headers = curl_slist_append(headers, "Authorization: Bearer <ACCESS_TOKEN>"); headers = curl_slist_append(headers, "Content-Type:"); headers = curl_slist_append(headers, "Dropbox-API-Arg: {\"path\":\"/test.txt\"}"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_URL, "https://content.dropboxapi.com/2/files/download"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ""); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); printf ("\nFinished curl test.\n"); } curl_global_cleanup(); printf ("Done!\n"); return 0; }
<ACCESS_TOKEN>应该用您的访问令牌代替。