• Welcome to Valhalla Legends Archive.
 

WinInet HttpSendRequest Fails

Started by Spilled, September 10, 2008, 11:50 PM

Previous topic - Next topic

Spilled

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:


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;
}


Does anyone see any problems? The MessageBox that contains the GetLastError return value prints "6". Thanks in advance.

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 =.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Kp

Quote from: l2k-Shadow on September 10, 2008, 11:57 PM
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 =.

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!