George
2008-09-19 03:14:00 UTC
Hello everyone,
I want to implement the shake hands of Windows Integrated Authentication for
myself. Here is a reference link of the protocol and steps of shakehands.
http://en.wikipedia.org/wiki/NTLM
I have tried a prototype using WinInet API below, and find each time when
using WinInet API InternetOpenUrl, this API will handle all underlying
authentication shakehands for me. :wave:
http://TestMachine/Monitor is a web site setup by IIS with Windows
Integrated Authentication, and the following invocation of InternetOpenUrl
will automatically returns 200 OK and will use my current login user's
credential automatically -- no change for me to parse return each time from
IIS and do the shakehands by myself.
My question is, could I use WinInet level API like InternetOpenUrl to
achieve my goal? Why?
My simple code.
[Code]
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <wininet.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
HINTERNET hINet = InternetOpen(TEXT("InetURL/1.0"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if ( !hINet )
{
return EXIT_FAILURE;
}
HINTERNET hFile = InternetOpenUrl( hINet,
TEXT("http://TestMachine/Monitor"), NULL, 0, 0, 0 );
if(hFile)
{
CHAR buffer[1024]={0};
DWORD dwRead;
while ( InternetReadFile( hFile, buffer, 1023, &dwRead ) )
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
cout << buffer << endl;
}
InternetCloseHandle( hFile );
}
InternetCloseHandle(hINet);
return EXIT_SUCCESS;
}
[/Code]
thanks in advance,
George
I want to implement the shake hands of Windows Integrated Authentication for
myself. Here is a reference link of the protocol and steps of shakehands.
http://en.wikipedia.org/wiki/NTLM
I have tried a prototype using WinInet API below, and find each time when
using WinInet API InternetOpenUrl, this API will handle all underlying
authentication shakehands for me. :wave:
http://TestMachine/Monitor is a web site setup by IIS with Windows
Integrated Authentication, and the following invocation of InternetOpenUrl
will automatically returns 200 OK and will use my current login user's
credential automatically -- no change for me to parse return each time from
IIS and do the shakehands by myself.
My question is, could I use WinInet level API like InternetOpenUrl to
achieve my goal? Why?
My simple code.
[Code]
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <wininet.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
HINTERNET hINet = InternetOpen(TEXT("InetURL/1.0"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if ( !hINet )
{
return EXIT_FAILURE;
}
HINTERNET hFile = InternetOpenUrl( hINet,
TEXT("http://TestMachine/Monitor"), NULL, 0, 0, 0 );
if(hFile)
{
CHAR buffer[1024]={0};
DWORD dwRead;
while ( InternetReadFile( hFile, buffer, 1023, &dwRead ) )
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
cout << buffer << endl;
}
InternetCloseHandle( hFile );
}
InternetCloseHandle(hINet);
return EXIT_SUCCESS;
}
[/Code]
thanks in advance,
George