InternetOpeNurl无法通过虚拟机起作用

发布于 2025-02-11 16:20:54 字数 1863 浏览 0 评论 0原文

Setup:
Oracle Virtual Box 6.1
Windows 7 Home Premium x86 and x64

我有以下从虚拟机中运行的Win7 32和64位的虚拟机的代码:

#include <iostream>
#include <Windows.h>
#include <WinInet.h>
#include <thread>

#pragma comment(lib, "wininet.lib")

using namespace std;

bool isURL_Redirected(wstring url)
{
    HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    if (hInternet)
    {
        hInternet = InternetOpenUrl(hInternet, url.c_str(), 0, 0, INTERNET_FLAG_NO_AUTO_REDIRECT, 0);
        WCHAR lpvData[1000];
        DWORD size = sizeof(lpvData);

        if (hInternet)
        {
            if (HttpQueryInfo(hInternet, HTTP_QUERY_LOCATION, lpvData, &size, NULL))
            {
                InternetCloseHandle(hInternet);
                return true;
            }
        }
        else
        {
            cout << "line 30: " << GetLastError() << endl;
        }
    }
    else
    {
        cout << "line 35: " << GetLastError() << endl;
    }

    InternetCloseHandle(hInternet);
    return false;
}

int main()
{
    if (isURL_Redirected(L"https://download.visualstudio.microsoft.com/download/pr/8e396c75-4d0d-41d3-aea8-848babc2736a/80b431456d8866ebe053eb8b81a168b3/ndp462-kb3151800-x86-x64-allos-enu.exe"))
        cout << "It does redirect." << endl;
    else
        cout << "It does not redirect." << endl;
    system("pause"); // Win only.
}

输出:

line 30: 12157

为什么它不从虚拟机来使用?它在真实的机器中正常工作。我注意到,如果将URL更改为 https://www.google.com 真正相信与URL和虚拟机有关系。有解决方法吗?

编辑

12157是内部的Wininet错误,通常是在无法加载其SSL/TLS库时。它与将密钥发送到HTTPS服务器无关。

Setup:
Oracle Virtual Box 6.1
Windows 7 Home Premium x86 and x64

I have the following code running from a Virtual Machine in both versions of win7 32 and 64 bit:

#include <iostream>
#include <Windows.h>
#include <WinInet.h>
#include <thread>

#pragma comment(lib, "wininet.lib")

using namespace std;

bool isURL_Redirected(wstring url)
{
    HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    if (hInternet)
    {
        hInternet = InternetOpenUrl(hInternet, url.c_str(), 0, 0, INTERNET_FLAG_NO_AUTO_REDIRECT, 0);
        WCHAR lpvData[1000];
        DWORD size = sizeof(lpvData);

        if (hInternet)
        {
            if (HttpQueryInfo(hInternet, HTTP_QUERY_LOCATION, lpvData, &size, NULL))
            {
                InternetCloseHandle(hInternet);
                return true;
            }
        }
        else
        {
            cout << "line 30: " << GetLastError() << endl;
        }
    }
    else
    {
        cout << "line 35: " << GetLastError() << endl;
    }

    InternetCloseHandle(hInternet);
    return false;
}

int main()
{
    if (isURL_Redirected(L"https://download.visualstudio.microsoft.com/download/pr/8e396c75-4d0d-41d3-aea8-848babc2736a/80b431456d8866ebe053eb8b81a168b3/ndp462-kb3151800-x86-x64-allos-enu.exe"))
        cout << "It does redirect." << endl;
    else
        cout << "It does not redirect." << endl;
    system("pause"); // Win only.
}

Outputs:

line 30: 12157

Why it does not work from a Virtual Machine? It works fine in a real machine though. I noticed that if I change the URL to https://www.google.com it works fine, so I truly believe there's something to do with the URL and the Virtual Machine. Is there a workaround for this?

EDIT

12157 is an internal WinInet error, usually when it can't load its SSL/TLS library. It has nothing to do with sending keys to the HTTPS server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文