1. Download failure causing CAD crash, error ‘Error handler re-entered. Exiting now’. The reason is that I inherited libcurl-related functions into a class and performed relevant WebAPI interactions within the class. However, because I made a request at the very beginning, I failed to initialize curl, leading to data transfer errors. It just needs to be initialized at the beginning of the function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
curl = curl_easy_init();
/*curl_global_init(CURL_GLOBAL_DEFAULT);*/
if (curl)
{
MessageBoxA(NULL, combinePath.c_str(), "0", 0);
FILE* fp = fopen(strFileName.c_str(), "wb"); // Open file, prepare to write
curl_easy_setopt(curl, CURLOPT_URL, combinePath.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);

CURLcode result = curl_easy_perform(curl);
acutPrintf(L"download : %i", result);
fclose(fp); // Close file
/*curl_easy_cleanup(curl);*/
}
  1. Requesting WebAPI data, found the interface unresponsive, and testing with string input separately had no effect. The reason is that my test file contained English characters, leading me to neglect encoding when passing it in. I kept testing ignoring this aspect. To solve this problem, encode Chinese characters before passing them into the header.
1
2
3
4
5
6
7
8
9
10
11
std::wstring_convert<codecvt_utf8<wchar_t>> converter;

//std::wstring wideStr = L"Special Chapter Template";
std::wstring wideStr = ConvertToWideString(Filepath);
// Convert to UTF-8 encoding
std::string utf8Str = converter.to_bytes(wideStr);

// Perform URL encoding
char* encodedData = curl_easy_escape(curl, utf8Str.c_str(), utf8Str.length());
std::string encodedSymbolName(encodedData);
curl_free(encodedData);

URLEncode function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
std::string webApi::UrlEncode(const std::string& str)
{
std::string strTemp = "";
size_t length = str.length();
for (size_t i = 0; i < length; i++)
{
if (isalnum((unsigned char)str[i]) ||
(str[i] == '-') ||
(str[i] == '_') ||
(str[i] == '.') ||
(str[i] == '~'))
strTemp += str[i];
else if (str[i] == ' ')
strTemp += "+";
else
{
strTemp += '%';
strTemp += ToHex((unsigned char)str[i] >> 4);
strTemp += ToHex((unsigned char)str[i] % 16);
}
}
return strTemp;

}