char azTemp [255];
char azUserName [] = "domainname\\azUserName";
char azPassWD [] = "password";
char *azBuffer;
long aiActSize;
long aiRetVal;
DWORD aiStatus;
DWORD aiBytesRead;
DWORD aiSize;
DWORD aiSizeLen;
DWORD aiUsrNameSize = sizeof (azUserName);
DWORD aiPassWdSize = sizeof (azPassWD);
DWORD aiStatusSize = sizeof (aiStatus);
HINTERNET aoINetSession;
HINTERNET aoINetConnect;
HINTERNET aoINetHandle;
aoINetSession = ::InternetOpen ( "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
EXIT_WHEN_VALUE_ZERO (aoINetSession);
aoINetConnect = ::InternetConnect ( aoINetSession, "http://www.rediff.com/", INTERNET_DEFAULT_HTTP_PORT, 0, 0, INTERNET_SERVICE_HTTP, NULL, NULL );
EXIT_WHEN_VALUE_ZERO (aoINetConnect);
aoINetHandle = ::HttpOpenRequest( aoINetConnect, "GET", "/", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );
EXIT_WHEN_VALUE_ZERO (aoINetHandle);
Resend:
aiRetVal = ::HttpSendRequest (aoINetHandle, NULL, 0, NULL, 0);
aiRetVal = ::HttpQueryInfo (aoINetHandle, HTTP_QUERY_FLAG_NUMBER HTTP_QUERY_STATUS_CODE, &aiStatus, &aiStatusSize, NULL);
switch (aiStatus) {case HTTP_STATUS_PROXY_AUTH_REQ: // Proxy Authentication RequiredaiRetVal = ::InternetSetOption (aoINetHandle, INTERNET_OPTION_PROXY_UserName, azUserName, aiUsrNameSize);
aiRetVal = ::InternetSetOption (aoINetHandle, INTERNET_OPTION_PROXY_PASSWORD, azPassWD, aiPassWdSize);
goto Resend;
break;
case HTTP_STATUS_DENIED: //Server Authentication RequiredaiRetVal = ::InternetSetOption (aoINetHandle, INTERNET_OPTION_UserName, azUserName, aiUsrNameSize);
aiRetVal = ::InternetSetOption (aoINetHandle, INTERNET_OPTION_PASSWORD, azPassWD, aiPassWdSize);
goto Resend;
break;}
aiSizeLen = 255;
aiRetVal = ::HttpQueryInfo (aoINetHandle, HTTP_QUERY_CONTENT_LENGTH, azTemp, &aiSizeLen, NULL);
if (aiRetVal != 0) {trim (azTemp);aiActSize = ::atol (azTemp);
} else {aiActSize = 24576;
// some max size}
azBuffer = new char [aiActSize + 1];aiSize = 0;
while (true) { aiRetVal = ::InternetReadFile ( aoINetHandle, azBuffer + aiSize, 255, &aiBytesRead );
if (aiRetVal == 0) break;
if (aiBytesRead == 0) break;
aiSize += aiBytesRead;}
azBuffer [aiSize] = 0;
write_2_file ("out.htm", azBuffer);
delete [] azBuffer;
::InternetCloseHandle (aoINetSession);::InternetCloseHandle (aoINetConnect);::InternetCloseHandle (aoINetHandle);
return 0;
Safe, High performance, reuseable
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment