std::wstring gitHubApiUrl = L"https://api.github.com/Test";
URL_COMPONENTSW urlComponents = {};
urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
// Buffers for host and path
wchar_t hostName[256] = {};
wchar_t urlPath[1024] = {};
urlComponents.lpszHostName = hostName;
urlComponents.dwHostNameLength = ARRAYSIZE(hostName);
urlComponents.lpszUrlPath = urlPath;
urlComponents.dwUrlPathLength = ARRAYSIZE(urlPath);
// Call WinHttpCrackUrl
if (!WinHttpCrackUrl(gitHubApiUrl.c_str(), 0, 0, &urlComponents)) {
std::wcerr << L"Failed to parse URL. Error: " << GetLastError() << std::endl;
return;
}
// Output parsed components
std::wcout << L"Scheme: ";
switch (urlComponents.nScheme) {
case INTERNET_SCHEME_HTTP: std::wcout << L"HTTP"; break;
case INTERNET_SCHEME_HTTPS: std::wcout << L"HTTPS"; break;
default: std::wcout << L"Other (" << urlComponents.nScheme << L")"; break;
}
std::wcout << std::endl;
std::wcout << L"Host Name: " << urlComponents.lpszHostName << std::endl;
std::wcout << L"URL Path: " << urlComponents.lpszUrlPath << std::endl;
运行上述代码后,输出结果不是https,而是Other(2)。为什么会出现这种情况? 运行环境为win10 x64系统。