Discussion:
HttpOpenRequest brings up error 122: ERROR_INSUFFICIENT_BUFFER (no url limit problems, just default params)
(too old to reply)
Daniel Kondermann
2005-03-27 20:09:43 UTC
Permalink
Hi there!

According to the Platform SDK these calls shouldn't do any harm:

HINTERNET m_hInternet = InternetOpen(Agent.c_str(),
PRE_CONFIG_INTERNET_ACCESS, NULL, 0, 0);

HINTERNET m_hConnection =InternetConnect(
m_hInternet, Server.c_str(), Port, NULL /*username*/, NULL
/*password*/,
INTERNET_SERVICE_HTTP, 0, 0);

DWORD err =GetLastError(); //returns "no error"

HINTERNET m_hRequest =HttpOpenRequest(m_hConnection, NULL,
"/guard/guard.php\0",
NULL, "192.168.0.1\0", NULL, INTERNET_FLAG_RELOAD, 0);

err =GetLastError(); //returns Error 122: ERROR_INSUFFICIENT_BUFFER

Unfortunately I have no clue why the call to HttpOpenRequest returns
that error since I don't use any buffers. And m_hRequest is not NULL,
so it should be a correct handle. Anyway all subsequent calls will
fail with an "invalid handle" error.
Anyway the Platform SDK doesn't mention that this error can occur :(

I'd very much appreciate your help!
...theres not much info about this stuff in the web...
Daniel
Stephen Sulzer
2005-03-28 03:01:57 UTC
Permalink
In Win32 API programming, you don't check GetLastError unless the Win32 API
that you called indicated that it failed (usually by returning FALSE or a
NULL handle). So if HttpOpenRequest is returning a non-NULL request handle
then HttpOpenRequest succeeded and GetLastError is irrelevant.

- Stephen
Post by Daniel Kondermann
Hi there!
HINTERNET m_hInternet = InternetOpen(Agent.c_str(),
PRE_CONFIG_INTERNET_ACCESS, NULL, 0, 0);
HINTERNET m_hConnection =InternetConnect(
m_hInternet, Server.c_str(), Port, NULL /*username*/, NULL
/*password*/,
INTERNET_SERVICE_HTTP, 0, 0);
DWORD err =GetLastError(); //returns "no error"
HINTERNET m_hRequest =HttpOpenRequest(m_hConnection, NULL,
"/guard/guard.php\0",
NULL, "192.168.0.1\0", NULL, INTERNET_FLAG_RELOAD, 0);
err =GetLastError(); //returns Error 122: ERROR_INSUFFICIENT_BUFFER
Unfortunately I have no clue why the call to HttpOpenRequest returns
that error since I don't use any buffers. And m_hRequest is not NULL,
so it should be a correct handle. Anyway all subsequent calls will
fail with an "invalid handle" error.
Anyway the Platform SDK doesn't mention that this error can occur :(
I'd very much appreciate your help!
...theres not much info about this stuff in the web...
Daniel
Daniel Kondermann
2005-03-28 08:34:12 UTC
Permalink
Thanks for your fast reply!
The reason for my question is that in the following line of code:

if(!HttpSendRequest(m_hRequest, NULL, 0, NULL, 0)) {
err =GetLastError(); //returns 6: "Invalid Handle"
}

I get an "Invalid Handle" error. Thus it seems like the first call
failed even though it returned a handle different from NULL.
What am I doing wrong?

Thanks again,
Daniel
Post by Daniel Kondermann
HINTERNET m_hInternet = InternetOpen(Agent.c_str(),
PRE_CONFIG_INTERNET_ACCESS, NULL, 0, 0);
HINTERNET m_hConnection =InternetConnect(
m_hInternet, Server.c_str(), Port, NULL /*username*/, NULL
/*password*/,
INTERNET_SERVICE_HTTP, 0, 0);
DWORD err =GetLastError(); //returns "no error"
HINTERNET m_hRequest =HttpOpenRequest(m_hConnection, NULL,
"/guard/guard.php\0",
NULL, "192.168.0.1\0", NULL, INTERNET_FLAG_RELOAD, 0);
err =GetLastError(); //returns Error 122: ERROR_INSUFFICIENT_BUFFER
Daniel Kondermann
2005-03-28 12:38:21 UTC
Permalink
Hi there!

I found the problem - basically it was several mistakes I did at once,
thus it was a little harder to find it.
First I called InternetCloseHandle() before calling GetLastError. So I
got the "Invalid Handle".
Then I tried to figure out why HttpSendRequest returned false but my
Error Handling Routing didn't return any error _string_. The error
code was 12007 and this is not correctly translated by FormatMessage
(or I used the wrong params).
Finally I found out that I just used the wrong Server name with a
leading "http://" which wasn't supposed to be there.
Now it works fine :)

Daniel

"The two most common elements in the universe are hydrogen and
stupidity."
- Harlan Ellison
Post by Daniel Kondermann
Hi there!
HINTERNET m_hInternet = InternetOpen(Agent.c_str(),
PRE_CONFIG_INTERNET_ACCESS, NULL, 0, 0);
HINTERNET m_hConnection =InternetConnect(
m_hInternet, Server.c_str(), Port, NULL /*username*/, NULL
/*password*/,
INTERNET_SERVICE_HTTP, 0, 0);
DWORD err =GetLastError(); //returns "no error"
HINTERNET m_hRequest =HttpOpenRequest(m_hConnection, NULL,
"/guard/guard.php\0",
NULL, "192.168.0.1\0", NULL, INTERNET_FLAG_RELOAD, 0);
err =GetLastError(); //returns Error 122: ERROR_INSUFFICIENT_BUFFER
Unfortunately I have no clue why the call to HttpOpenRequest returns
that error since I don't use any buffers. And m_hRequest is not NULL,
so it should be a correct handle. Anyway all subsequent calls will
fail with an "invalid handle" error.
Anyway the Platform SDK doesn't mention that this error can occur :(
I'd very much appreciate your help!
...theres not much info about this stuff in the web...
Daniel
Stephen Sulzer
2005-03-28 18:23:52 UTC
Permalink
Post by Daniel Kondermann
Hi there!
I found the problem - basically it was several mistakes I did at once,
thus it was a little harder to find it.
First I called InternetCloseHandle() before calling GetLastError. So I
got the "Invalid Handle".
Then I tried to figure out why HttpSendRequest returned false but my
Error Handling Routing didn't return any error _string_. The error
code was 12007 and this is not correctly translated by FormatMessage
(or I used the wrong params).
Finally I found out that I just used the wrong Server name with a
leading "http://" which wasn't supposed to be there.
Now it works fine :)
Daniel
"The two most common elements in the universe are hydrogen and
stupidity."
- Harlan Ellison
Post by Daniel Kondermann
Hi there!
HINTERNET m_hInternet = InternetOpen(Agent.c_str(),
PRE_CONFIG_INTERNET_ACCESS, NULL, 0, 0);
HINTERNET m_hConnection =InternetConnect(
m_hInternet, Server.c_str(), Port, NULL /*username*/, NULL
/*password*/,
INTERNET_SERVICE_HTTP, 0, 0);
DWORD err =GetLastError(); //returns "no error"
HINTERNET m_hRequest =HttpOpenRequest(m_hConnection, NULL,
"/guard/guard.php\0",
NULL, "192.168.0.1\0", NULL, INTERNET_FLAG_RELOAD, 0);
err =GetLastError(); //returns Error 122: ERROR_INSUFFICIENT_BUFFER
Unfortunately I have no clue why the call to HttpOpenRequest returns
that error since I don't use any buffers. And m_hRequest is not NULL,
so it should be a correct handle. Anyway all subsequent calls will
fail with an "invalid handle" error.
Anyway the Platform SDK doesn't mention that this error can occur :(
I'd very much appreciate your help!
...theres not much info about this stuff in the web...
Daniel
Stephen Sulzer
2005-03-28 18:28:36 UTC
Permalink
Post by Daniel Kondermann
Then I tried to figure out why HttpSendRequest returned false but my
Error Handling Routing didn't return any error _string_. The error
code was 12007 and this is not correctly translated by FormatMessage
(or I used the wrong params).
In order to use FormatMessage with the WinInet error codes, you must specify
the FORMAT_MESSAGE_FROM_HMODULE flag and the handle of the WinInet module
(as the lpSource parameter). Using FORMAT_MESSAGE_FROM_SYSTEM will not work
for WinInet error codes.

Example:

LPVOID lpMsgBuffer;

FormatMessage(FORMAT_MESSAGE_F­ROM_HMODULE |
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandle("wininet.dll")­,
dwErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuffer,
0, // FormatMessage allocs buffer; use LocalFree to free
NULL);


Hope that helps.

- Stephen

Loading...