InternetOpen can not work well  
Author Message
langev





PostPosted: Visual C++ General, InternetOpen can not work well Top

When i use the follow code to send some data to a asp file,in the beginning ,it works well,but some time later,the exception arise,what can i to do

the code are as follow:

while(1)
{
hInternet = InternetOpen("ww",PRE_CONFIG_INTERNET_ACCESS,NULL,0,0 );
hHttpConnection = InternetConnect(hInternet,www.google.com,80,
"","",INTERNET_SERVICE_HTTP ,0,0);
hRequest=HttpOpenRequest(hHttpConnection,"POST",HTTP_VERSION ,NULL, 0 ,INTERNET_FLAG_DONT_CACHE ,0);
HttpSendRequest(hRequest,NULL,-1,DATA,sizeof(DATA));

while(BytesRead != 0)
{
InternetReadFile(hRequest,lpszBuffer,BytesToRead,&BytesRead);
printf("%s",lpszBuffer);
ZeroMemory(lpszBuffer,sizeof(lpszBuffer));
count++;
}
InternetCloseHandle(hInternet);
InternetCloseHandle(hHttpConnection);
InternetCloseHandle(hRequest);

Sleep(20000);
}

when i use getlasterror() function, i find the error code is 120001,and the cpu usage is 100%.

can you help me, thank you!




Visual C++7  
 
 
Viorel.





PostPosted: Visual C++ General, InternetOpen can not work well Top

Maybe handles must be closed in reverse order I.e.:

InternetCloseHandle(hRequest);

InternetCloseHandle(hHttpConnection);

InternetCloseHandle(hInternet);