Search code examples
c++windowsmfcwindows-vistawininet

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


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.

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.

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();

Solution

  • 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).

    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.


    Edit: In addition to testing the MFC fragment separately as I suggested in the comments below, it may be worthwhile to try it the standard WinAPI way -- the idea being, if there's something wrong with the wininet library on your computer, this code should also fail to connect:

    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)