I am using libcurl
and able to receive json response
and saving it to file
.
Below is the code
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string.h>
#define URL "http://www.joes-hardware.com/tools.html"
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(void) {
CURL *curl;
FILE *fp;
CURLcode res;
//char *url = "http://www.joes-hardware.com/tools.html";
char *url= URL;
char outfilename[FILENAME_MAX] = "./json";
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"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);
}
return 0;
}
As part of the application which I am developing, now it has to fetch a zip
file from the server.
Suppose the URL
is of the format shown below:
#define URL "https://Server/File.zip"
For such URL, the code is not able to save the zip
file.
How to achieve this?
I am developing for LINUX
platform.
Resolved the Issue. Problem was with
HTTPS connection
Addedcertificate
Based on below links:Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?
Getting no content from a HTTPS connection using CURL