嗨,我正在嘗試為我的項目測試libcurl,但是當我想下載一個測試文件時,我得到一個錯誤:
ERROR : Unknown error
但沒有理由,我的代碼:
#include <stdio.h>
#include <curl/curl.h>
int main(int argc, char **argv) {
CURL *curl;
FILE *fp;
char name[30] = {"Test"};
char link[100] = {"ipv4.download.thinkbroadband.com/5MB.zip"};
CURLcode error;
int result;
fp = fopen(name,"Wb");
curl = curl_easy_init();
curl_easy_setopt;(curl, CURLOPT_URL, argv[1] );
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_perform(curl);
result = curl_easy_perform(curl);
if (result = CURLE_OK)
printf("Sucessful download !");
else
printf("Could not download, ERROR : %s \n",curl_easy_strerror(error));
printf("%s",error);
fclose(fp);
curl_easy_cleanup(curl);
}
你知道為什么嗎?!
代碼中有很多錯誤。
fopen
的參數應該是小寫的“w”。error
和result
,但應該只使用一個。curl_easy_setopt;(curl, CURLOPT_URL, argv[1] );
結合前面提到的內容,這應該是可行的:
別忘了把URL作為參數傳遞,因為您實際上沒有使用
link
,也沒有選中argc
。我建議你學習如何使用調試器。