Valhalla Legends Forums Archive | C/C++ Programming | WinInet HttpSendRequest Fails

AuthorMessageTime
Spilled[DW]
Hello All I am trying to pass Basic Authentication using WinInet and I am having some issues. As of right now, My call to HttpSendRequest() Fails. Following th is failure I call GetLastError() which is returning 6 and I cannot find any Information on this error value return so I'm posting for some help. Right now im using my router basic authentication to test my program (Yes I have tested it against Basic Auth Sites - Same problem). Here is my code:

[Code]
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
HINTERNET openHandle, connectHandle, resourceHandle;
DWORD status;
DWORD statusSize = sizeof(status);
memset(&status, 0, sizeof(DWORD));
openHandle = InternetOpen("HTTP",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(openHandle = NULL){
MessageBox(NULL, "InternetOpen Failed!", NULL, MB_OK);
ExitThread(0);
}

connectHandle = InternetConnect(openHandle,"192.168.1.1",
INTERNET_INVALID_PORT_NUMBER, "User", "Pass",INTERNET_SERVICE_HTTP,0,0);
if(connectHandle = NULL){
MessageBox(NULL, "InternetConnect Failed!", NULL, MB_OK);
ExitThread(0);
}

resourceHandle = HttpOpenRequest(connectHandle,"GET","/","HTTP/1.1",NULL,NULL,
INTERNET_FLAG_KEEP_CONNECTION,0);

if(resourceHandle = NULL)
{
MessageBox(NULL, "HttpOpenRequest Failed!", NULL, MB_OK);
}else{
if(!HttpSendRequest(resourceHandle,NULL,0,NULL,0))
{
DWORD theError = GetLastError();
char tmp[200];
sprintf(tmp, "%d", theError);
MessageBox(NULL, tmp, "HttpSendRequest Failed", MB_OK);
ExitThread(0);
}
HttpQueryInfo(resourceHandle, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,
&status, &statusSize, NULL);
/*InternetCloseHandle(resourceHandle);
InternetCloseHandle(openHandle);
InternetCloseHandle(connectHandle);*/

switch (status)
{
case 4:
MessageBox(NULL, "4", NULL, MB_OK);
break;
case 400:
MessageBox(NULL, "400 - Bad Request", NULL, MB_OK);
break;
case 401: //401 - Server Authentication Required.
MessageBox(NULL, "Auth Required", NULL, MB_OK);
break;
case 200-207:
MessageBox(NULL, "200 Ok", NULL, MB_OK);
break;
case 404:
MessageBox(NULL, "404 - Not Found", NULL, MB_OK);
break;
case 403:
MessageBox(NULL, "403 - Forbidden", NULL, MB_OK);
break;
case 405:
MessageBox(NULL, "405 - HTTP Method Not Allowed.", NULL, MB_OK);
break;
case 407:
MessageBox(NULL, "407 - Proxy Authentication Required.", NULL, MB_OK);
break;
case 301-302: case 304: case 307:
MessageBox(NULL, "3xx", NULL, MB_OK);
break;
case 500:
MessageBox(NULL, "500 - Server Internal Error", NULL, MB_OK);
break;
default:
{
char f = (char)status;
MessageBox(NULL, "Default", (const char*)f, MB_OK);
}
break;
}
}
ExitThread(0);
return 0;
}
[/Code]

Does anyone see any problems? The MessageBox that contains the GetLastError return value prints "6". Thanks in advance.
September 11, 2008, 4:50 AM
l2k-Shadow
Error 6 is Invalid Handle.  This means that HttpOpenRequest or one of the previous calls is failing. Your error check if statements will not work, you are using incorrect syntax make the compiler compare the values, you need to use double equal signs, ==, instead of =.
September 11, 2008, 4:57 AM
Kp
[quote author=l2k-Shadow link=topic=17649.msg179766#msg179766 date=1221109067]
Error 6 is Invalid Handle.  This means that HttpOpenRequest or one of the previous calls is failing. Your error check if statements will not work, you are using incorrect syntax make the compiler compare the values, you need to use double equal signs, ==, instead of =.
[/quote]

Actually, since he is overwriting the handles instead of testing them, the prior calls may be working fine.  His attempts at testing ensure he always passes NULL to the subsequent calls.
September 13, 2008, 12:02 AM

Search