C

How to overcome ERROR_INTERNET_INVALID_CA error in C

ERROR_INTERNET_INVALID_CA (12045) – The function is unfamiliar with the Certificate Authority that generated the server’s certificate.

//...
DWORD invalidcaFlags, invalidcaFlagsLen = sizeof(invalidcaFlags);
requestAgain:
	if (!CLFU(HttpSendRequestA)(request, headers, headersSize, data, dataSize)) {
		if (GetLastError() == ERROR_INTERNET_INVALID_CA) {
 
			InternetQueryOption(request, INTERNET_OPTION_SECURITY_FLAGS,
				(LPVOID)&Flags, &FlagsLen);
 
			Flags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
 
			InternetSetOption(request, INTERNET_OPTION_SECURITY_FLAGS,
				&Flags, sizeof(Flags));
 
			goto requestAgain;
		}
 
		CLFU(InternetCloseHandle)(request);
		return NULL;
	}
//..