gpt4 book ai didi

c++ - 在调用 InternetGetProxyInfo() 之前应该进行哪些初始化?

转载 作者:行者123 更新时间:2023-11-30 04:10:11 25 4
gpt4 key购买 nike

我将 Internet Explorer 配置为使用本地 PAC 文件: ie proxy settings

它工作得很好。但是当我尝试调用 InternetGetProxyInfo() 时,它失败并显示 ERROR_CAN_NOT_COMPLETE。可能是什么问题?

#ifndef WINVER              // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif

#include <winsock2.h>
#include <windows.h>
#include <wininet.h>
#include <tchar.h>

#define URL "http://www.yandex.ru/"
#define HOST "www.yandex.ru"

int _tmain(int argc, _TCHAR* argv[])
{
char proxyBuffer[1024];
char *str = proxyBuffer;
DWORD nb = 1024;
DWORD dw;
BOOL b;
pfnInternetGetProxyInfo pIGPI; // Function-pointer instance

/* code from MSDN: */
{
HMODULE hModJS; // Handle for loading the DLL

hModJS = LoadLibrary( TEXT("jsproxy.dll") );
if (!hModJS)
{
_tprintf( TEXT("\nLoadLibrary failed to load jsproxy.dll with error: %d\n"),
GetLastError( ) );
return( FALSE );
}

pIGPI = (pfnInternetGetProxyInfo)
GetProcAddress( hModJS, "InternetGetProxyInfo" );
if (!pIGPI)
{
_tprintf( TEXT("\nGetProcAddress failed to find InternetGetProxyInfo, error: %d\n"),
GetLastError( ) );
return( FALSE );
}

// The pIGPI function pointer can now be used to call InternetGetProxyInfo.
}

InternetInitializeAutoProxyDll(0); /* wininet.dll version of this function */
SetLastError(0);
b = pIGPI(URL,sizeof(URL),HOST,sizeof(HOST), &str, &nb);
dw = GetLastError();

SetLastError(0);
b = pIGPI(URL,sizeof(URL)-1,HOST,sizeof(HOST)-1, &str, &nb);
dw = GetLastError();

return 0;
}

请不要告诉我使用其他 API,这是一个教育性而非实际性的问题。

最佳答案

有两种方式:

  • 简单:使用虚拟 URL 调用 InternetOpenUrl()wininet 初始化 jsproxy:

    #define URL "https://yandex.ru:777"
    #define HOST "yandex.ru"
    HINTERNET hInternet = InternetOpen(_T("try-wininet"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    HINTERNET hUrl = InternetOpenUrl(hInternet, _T("http://0.0.0.0"), NULL, 0, 0, 20);
    InternetCloseHandle(hUrl);
    InternetCloseHandle(hInternet);
    InternetGetProxyInfo(URL,sizeof(URL)-1,HOST,sizeof(HOST)-1, &str, &nb);
    GlobalFree(str);
  • 困难:在 jsproxy 中调用 InternetInitializeAutoProxyDll()。但是要准备参数,您必须自己做所有事情:从注册表中读取设置、解析它们、检测并下载 PAC 文件并提供 AutoProxyHelperVtbl 的实现,其中包含 等功能GetIPAddress()IsInNet()

InternetGetProxyInfo() 在没有配置 PAC 脚本时失败,尽管在对话框底部设置了一些代理服务器。在这种情况下,您应该调用 InternetQueryOption(NULL, INTERNET_OPTION_PROXY,...)

关于c++ - 在调用 InternetGetProxyInfo() 之前应该进行哪些初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com