插件使用curl类库做HTTP请求,到WEB服务器下载需要的文件。服务器上的字体文件全都是ZIP文件,所以下载下来后,需要解压。另外,如果没有下载到需要的字体,则会通过WEB服务器的report_missing_cad_font这个API,报告服务器。

CURL*curl;CURLcoderes;FILE*fp;wstringfullPath=FontBasicPath+ L"\\"+fontName+ L".zip";_wfopen_s(&fp,fullPath.c_str(), L"wb");//创建ZIP文件if(fp==NULL) {return false;
    }transform(fontName.begin(),fontName.end(),fontName.begin(),towlower);boolresult=false;curl=curl_easy_init();if(curl) {curl_easy_setopt(curl,CURLOPT_URL, (DownloadCadFontUrl+"/"+WStringToUTF8(fontName.c_str()) +".zip").c_str());curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_file_data);curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp);res=curl_easy_perform(curl);//请求服务器if(CURLE_OK==res) {fclose(fp);char*ct;res=curl_easy_getinfo(curl,CURLINFO_CONTENT_TYPE, &ct);if((CURLE_OK==res) &&ct) {std::stringcontentType(ct);curl_easy_cleanup(curl);if(contentType=="application/zip") {//判断下载文件的类型result=true;//如果不是"application/zip"类型,就说明服务器上也没有这个字体}else{CURL*reportCurl;reportCurl=curl_easy_init();curl_easy_setopt(reportCurl,CURLOPT_URL,ReportMissingCadFontUrl.c_str());stringpostData="keyword="+WStringToUTF8(fontName.c_str());curl_easy_setopt(reportCurl,CURLOPT_POSTFIELDS,postData.c_str());res=curl_easy_perform(reportCurl);curl_easy_cleanup(reportCurl);
                }
            }
        }
    }
五、上传客户端字体到服务器