Error 122 on HttpOpenRequest

Giganews Newsgroups
Subject: Error 122 on HttpOpenRequest
Posted by:  DG (grot…@gmail.com)
Date: 13 Mar 2005

Hiya.

Trying a real simple example i found on another site. But doing a
GetLastError() after the HttpOpenRequest reveals a 122 error, which is
Insufficient Buffer or something similar. I cannot see where or why
this is happening. Subsequently, the actual call to HttpSendRequest
returns false. Code is as follows. The code compiles and otherwise runs
fine :). Please advise.

LPCTSTR lpszServerName = "http://192.168.1.3/";
LPCTSTR lpszObjectName = "/";

LPCTSTR lpszAgent = "WinInetGet/0.1";
HINTERNET hInternet = InternetOpen(lpszAgent,
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hInternet)
{
fprintf(stderr, "InternetOpen failed, error = %d (0x%x)
",
GetLastError(), GetLastError());
return;
}

INTERNET_PORT nServerPort = INTERNET_DEFAULT_HTTP_PORT;
LPCTSTR lpszUserName = NULL;
LPCTSTR lpszPassword = NULL;
DWORD dwConnectFlags = 0;
DWORD dwConnectContext = 0;

HINTERNET hConnect = InternetConnect(hInternet, lpszServerName,
nServerPort,
lpszUserName, lpszPassword,INTERNET_SERVICE_HTTP,dwConnectFlags,
dwConnectContext);
if (!hConnect)
{
InternetCloseHandle(hInternet);
fprintf(stderr, "InternetConnect failed, error = %d (0x%x)
",
GetLastError(), GetLastError());
return;
}

LPCTSTR lpszVerb = "GET";
LPCTSTR lpszVersion = NULL;            // Use default.
LPCTSTR lpszReferrer = NULL;        // No referrer.
LPCTSTR *lplpszAcceptTypes = NULL;    // Whatever the server wants to
give.
DWORD dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
        INTERNET_FLAG_KEEP_CONNECTION |                            INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD;

DWORD dwOpenRequestContext = 0;

HINTERNET hRequest = HttpOpenRequest(hConnect, lpszVerb,
lpszObjectName, lpszVersion,lpszReferrer,
lplpszAcceptTypes,dwOpenRequestFlags,dwOpenRequestContext);
if (!hRequest)
{
    InternetCloseHandle(hConnect);
    InternetCloseHandle(hInternet);
    fprintf(stderr, "HttpOpenRequest failed, error = %d (0x%x)
",
GetLastError(), GetLastError());
    return;
}

BOOL bResult = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
if (!bResult)
{
    InternetCloseHandle(hRequest);
    InternetCloseHandle(hConnect);
    InternetCloseHandle(hInternet);
    fprintf(stderr, "HttpSendRequest failed, error = %d (0x%x)
",
GetLastError(), GetLastError());
    return;
}

Replies