“有没有更好的办法?” Windows Vista 上的 wininet 出现错误 12029

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1291324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:00:26  来源:igfitidea点击:

"Is there a better way?" Error 12029 with wininet on Windows Vista

c++windowsmfcwindows-vistawininet

提问by JohnG

I kept recieving error 12029 (ERROR INTERNET CANNOT CONNECT, The attempt to connect to the server failed.) when using the the MFC wininet classes on Windows Vista. The cause of the error was due to Windows Defender. Is there a better way to get around this than completely turning off Windows Defender? I tried turning off "real time protection" to no avail, I had to completely turn WD off to stop the 12029 errors.

在 Windows Vista 上使用 MFC wininet 类时,我一直收到错误 12029(错误互联网无法连接,尝试连接到服务器失败。)。错误的原因是由于 Windows Defender。有没有比完全关闭 Windows Defender 更好的方法来解决这个问题?我尝试关闭“实时保护”无济于事,我不得不完全关闭 WD 以阻止 12029 错误。

If there is no better solution hopefully someone else with the same issue will see this question and be able to fix thier own problem. I searched the intertubes high and low and didn't find any crossreferences between wininet error 12029 and WD.

如果没有更好的解决方案,希望有同样问题的其他人会看到这个问题并能够解决他们自己的问题。我搜索了高低之间的管间,并没有发现 wininet 错误 12029 和 WD 之间的任何交叉引用。

My code for reference

我的代码供参考

::CInternetSession session;
::CHttpConnection* connection = session.GetHttpConnection(L"twitter.com",80,m_csUserName,m_csPassword);   
::CHttpFile* httpfile = connection->OpenRequest(CHttpConnection::HTTP_VERB_GET,L"/account/verify_credentials.xml");             
httpfile->SendRequest();

采纳答案by GRB

If Windows Defender displays a warning message after blocking your program, you should have the option to add your program to a list of "allowed items" which will allow it to run unencumbered while real time protection remains enabled. Admittedly, this is only a viable option if you are working with non-production/personal code (and if Defender is even displaying a warning message at all).

如果 Windows Defender 在阻止您的程序后显示警告消息,您应该可以选择将您的程序添加到“允许的项目”列表中,这将允许它在实时保护保持启用的同时不受阻碍地运行。诚然,如果您正在使用非生产/个人代码(如果 Defender 甚至显示警告消息),这只是一个可行的选择。

That said, it is possible that Defender has detected some possible risk based on the way you are using the wininet library -- would it be possible to use lower-level sockets instead? If this is the only network code you use, it would be easy to replicate it through the generic winsock library and there's a good chance that Defender would be much less inclined to block your program if you use it instead of wininet.

也就是说,根据您使用 wininet 库的方式,Defender 可能检测到了一些可能的风险——是否可以使用较低级别的套接字?如果这是您使用的唯一网络代码,则可以通过通用 winsock 库轻松复制它,并且如果您使用它而不是 wininet,Defender 很有可能不会阻止您的程序。



Edit编辑:除了像我在下面的评论中建议的那样单独测试 MFC 片段之外,尝试使用标准的 WinAPI 方式可能是值得的——这个想法是,如果你的计算机上的 wininet 库有问题,这段代码应该也无法连接:

int read = 0;
char* str = "*/*", buff[1024] = {};
HINTERNET inet = InternetOpen("GRB", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!(inet=InternetConnect(inet, "twitter.com", 80, "username", "password", INTERNET_SERVICE_HTTP, 0, 0))) 
    cout << "conn failed" << endl;
if (!(inet=HttpOpenRequest(inet, "GET", "/account/verify_credentials.xml", NULL, NULL, (const char**)&str, 0, 0))) 
    cout << "open failed" << endl;
if (!HttpSendRequest(inet, NULL, 0, NULL, 0)) 
    cout << "send failed" << endl;
InternetReadFile(inet, buff, 1023, (DWORD*)&read);
cout << buff << endl;
system("pause");

(designed to be a console program, be sure to include the correct headers/libraries)

(设计为控制台程序,确保包含正确的标题/库)