我正在使用 libcurl 从 Windows azure 下载 blob,该 blob 已公开并能够通过 http 站点成功下载。但是,如果 azure blob 存储使用自签名证书和私钥设为私有,则文件下载失败并显示消息“指定的资源不存在”
代码如下
CURL *curl;
FILE *fp;
CURLcode res;
bool success = true;
string CloudContainerPath = "https://MyTest.blob.core.windows.net/Mytest/";
string path = CloudContainerPath+fileNameJsonVal.asCString();
char *url = &path[0];
char *outfilename = (char *)fileNameJsonVal.asCString();
char errbuf[CURL_ERROR_SIZE];
int length = 0;
errbuf[0] = '\0';
static const char *pCACertFile = "D:\\LibCURL\\cacert.pem";
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
* set the file with the certs vaildating the server */
curl_easy_setopt(curl, CURLOPT_CAPATH,pCACertFile);
curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
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);