Моя цель - получить CSV или XLS из указанного c URL, используя Cpp.
При открытии следующей ссылки
http://www.centrodeinformacao.ren.pt/userControls/GetExcel.aspx?T=CRG&P=01-01-2007&variation=PT
можно увидеть в инструментах браузера

a 302 redirect and the file being actually downloaded from the following URL
http://www.centrodeinformacao.ren.pt/_layouts/CI.GetExcel/SafeGetExcel.aspx?T=CRG&P=02-01-2007&variation=PT
as shown in the next image (Request URL)

If I go to any of the two links manually, the a .xls file downloads just fine so we might as well use the one after redirection.
I've decided to move on an use libcurl с Visual Studio 2017 на моем компьютере W10. Рекомендуемый способ включения libcurl в проект Visual Studio 2017 - использовать vcpkg , что я и использовал.
1. Установите vcpkg
- Откройте Git Bash, cd C: / Program Files / и клонируйте это репо .

- Открыть командную строку, cd C: / Program Files / vcpkg, запустить
bootstrap-vcpkg.bat

and after run vcpkg integrate install

2. Install libcurl
- Run
vcpkg install curl

3. Create a new project
- Simply create Visual C++ > Windows Desktop > Windows Console Application

to be able to use #include
right away
" />
4. Current Result
Then, inspired in the following answers
И используя следующий код
#include "pch.h"
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
void downloadFile(const char* url, const char* fname) {
CURL *curl;
FILE *fp;
CURLcode res;
curl = curl_easy_init();
if (curl) {
fp = fopen(fname, "wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
int main(void) {
downloadFile("http://www.centrodeinformacao.ren.pt/_layouts/CI.GetExcel/SafeGetExcel.aspx?T=CRG&P=01-01-2007&variation=PT", "C:\\Users\\molecoder\\Desktop\\test.csv");
}
Я вижу test.csv в нужной папке, но это пустой файл.
пустой CSV