WinHttpCrackUrl 函数出现错误 nScheme

问题描述 投票:0回答:1
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系统。

c++ winapi
1个回答
0
投票

INTERNET_SCHEME_HTTPS
值实际上是 2,如 winhttp.h 中所定义。

您的代码可能使用 wininet.h 值,即 4。

© www.soinside.com 2019 - 2024. All rights reserved.