简体   繁体   English

使用具有IP地址的InternetConnect失败(错误12029)

[英]Using InternetConnect with IP-address fails (error 12029)

Here i have a snippet that doesn't work when i'am using IP address. 在这里,我有一个片段,当我使用IP地址时不起作用。 But in MSDN it says that parameter could be dotted-decimal IP address, so it must work clearly. 但是在MSDN中,它说该参数可以是点分十进制IP地址,因此它必须清楚地工作。 What is wrong? 怎么了? Thank you. 谢谢。

#include "stdafx.h"        
        #include <windows.h>
        #include <wininet.h>
        #include <tchar.h>
        #include <iostream>        
        #pragma comment(lib,"wininet.lib")
        using namespace std;

        int _tmain(int argc, _TCHAR* argv[])
        {
            char szServer[] = "127.0.0.1";
            char szUrl[] = "/test/upload.php";
            char Data[] = "text123";
            char szHdrs[] =    "Content-Type: multipart/form-data; boundary=AaB03x";   
            char szTead[] =    "--AaB03x\r\n"
                               "Content-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\n"
                               "Content-Type: application/octet-stream\r\n"
                                "\r\n";
            char szTail[] =     "\r\n"
                                "--AaB03x--\r\n";
            char szUserAgent[] = "MyUA";
            char *szTypes[] = {"*/*", NULL};
            HINTERNET hIOpen = InternetOpenA(szUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
            if(!hIOpen)
            {
                printf("InternetOpenA Error\n");
            }
            HINTERNET hIConnect = InternetConnectA(hIOpen, szServer, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
            if(!hIConnect)
            {
                printf("InternetConnectA Error\n");
            }
            HINTERNET hHttpOpReq = HttpOpenRequestA(hIConnect, "POST", szUrl, NULL, NULL, (LPCSTR *)szTypes, 0, 1);
            if(!hHttpOpReq)
            {
                printf("HttpOpenRequestA Error\n");
            }
            BOOL bHttpSendReq = HttpSendRequestA(hHttpOpReq, szHdrs, strlen(szHdrs), Data, strlen(Data));
            if (!bHttpSendReq)
            {   int Error = GetLastError();
                printf("HttpSendRequest Error %d\n", Error);
            }


            system("pause");
            return 0;

        }

There is nothing more i can add, actually about this issue. 实际上,这个问题我无能为力了。 I'am using Windows 7 x64 Ultimate and VS2008. 我正在使用Windows 7 x64 Ultimate和VS2008。

Now i checked this .exe on other XP and Seven machines. 现在,我在其他XP和Seven计算机上检查了该.exe。 Looks like it works, but not on my machine. 看起来可行,但在我的机器上不起作用。 Maybe the problem is (out there) somewhere else. 也许问题出在其他地方。

Three hints: 三个提示:

  1. Add following flags to your internetconnect: 将以下标志添加到您的Internet连接:

    INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE INTERNET_FLAG_NO_CACHE_WRITE

  2. Also add http to your reqest: 还将http添加到您的请求中:

    char szServer[] = " http://127.0.0.1 "; char szServer [] =“ http://127.0.0.1 ”;

  3. You might also try with INTERNET_OPEN_TYPE_DIRECT instead of INTERNET_OPEN_TYPE_PRECONFIG 您也可以尝试使用INTERNET_OPEN_TYPE_DIRECT而不是INTERNET_OPEN_TYPE_PRECONFIG

in my code base I have a work around for a 12029 error, but it happens only when connection is lost during file downloading - to fix it I must fully close all WinInet handles and retry download. 在我的代码库中,我有12029错误的解决方法,但是仅在文件下载过程中连接丢失时才会发生-要解决此问题,我必须完全关闭所有WinInet句柄并重试下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM