Matthias Schmidt
2005-06-15 12:53:01 UTC
Hi all,
i have a problem with WININET and loggin in to a .NET webservice. All works
ok but the first time the call is made the user has to logon (the windows
login dialog pops up). My Question is: How can i configure Wininet with the
default credentials of the current logged in user? In .NET is use the line
webService.Credentials = CredentialCache.DefaultCredentials; and all works
fine.
Here is the pseudo code of my c++ Client:
HINTERNET hInternet = NULL;
HINTERNET hConnection = NULL;
HINTERNET hRequest = NULL;
hInternet = ::InternetOpen("SOAPCLIENT",
strProxy.GetLength() ?
(INTERNET_OPEN_TYPE_PRECONFIG | INTERNET_OPEN_TYPE_PROXY) :
INTERNET_OPEN_TYPE_DIRECT,
strProxy.GetLength() ? (LPCTSTR) strProxy : NULL,
NULL, 0);
hConnection = ::InternetConnect(hInternet,
url.GetHostName(),
(INTERNET_PORT)url.GetPortNumber(),
L"", L"",
INTERNET_SERVICE_HTTP,
INTERNET_FLAG_NO_UI,
NULL);
DWORD dwHttpsFlags = (url.GetScheme() == ATL_URL_SCHEME_HTTPS) ?
INTERNET_FLAG_SECURE : 0;
hRequest = ::HttpOpenRequest(hConnection, L"POST",
strUrl, HTTP_VERSION, NULL,
s_szAcceptTypes,
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_KEEP_CONNECTION | dwHttpsFlags, NULL);
DWORD dwError = 0;
DWORD dwStatusCode = 0;
DWORD dwStatusSize = sizeof(dwStatusCode);
bool flAgain = true;
// solange senden und mit vom Server benötigten Informationen anreichern, bis
// der Request durchläuft
while(flAgain)
{
BOOL flSend = ::HttpSendRequest(hRequest, strHeaders,
(DWORD)strHeaders.GetLength(),
(void *)(LPCSTR)writeStream.m_str,
writeStream.m_str.GetLength());
::HttpQueryInfo(hRequest,
HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE,
&dwStatusCode, &dwStatusSize, NULL);
switch(dwStatusCode)
{
case HTTP_STATUS_OK:
flAgain = false;
break;
case HTTP_STATUS_DENIED:
case HTTP_STATUS_PROXY_AUTH_REQ:
{
HWND hwndTop = ::GetForegroundWindow();
dwError = ::InternetErrorDlg(hwndTop, hRequest,
ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
NULL);
flAgain = (dwError == ERROR_INTERNET_FORCE_RETRY);
break;
}
default:
...
}
}
Thanks a lot
Matthias Schmidt
--
Matthias Schmidt mailto:***@sdm.de
sd&m AG http://www.sdm.de
software design & management
Berliner Str. 76, 63065 Offenbach am Main, Germany
Phone +49 69 82901-251, Fax -200
i have a problem with WININET and loggin in to a .NET webservice. All works
ok but the first time the call is made the user has to logon (the windows
login dialog pops up). My Question is: How can i configure Wininet with the
default credentials of the current logged in user? In .NET is use the line
webService.Credentials = CredentialCache.DefaultCredentials; and all works
fine.
Here is the pseudo code of my c++ Client:
HINTERNET hInternet = NULL;
HINTERNET hConnection = NULL;
HINTERNET hRequest = NULL;
hInternet = ::InternetOpen("SOAPCLIENT",
strProxy.GetLength() ?
(INTERNET_OPEN_TYPE_PRECONFIG | INTERNET_OPEN_TYPE_PROXY) :
INTERNET_OPEN_TYPE_DIRECT,
strProxy.GetLength() ? (LPCTSTR) strProxy : NULL,
NULL, 0);
hConnection = ::InternetConnect(hInternet,
url.GetHostName(),
(INTERNET_PORT)url.GetPortNumber(),
L"", L"",
INTERNET_SERVICE_HTTP,
INTERNET_FLAG_NO_UI,
NULL);
DWORD dwHttpsFlags = (url.GetScheme() == ATL_URL_SCHEME_HTTPS) ?
INTERNET_FLAG_SECURE : 0;
hRequest = ::HttpOpenRequest(hConnection, L"POST",
strUrl, HTTP_VERSION, NULL,
s_szAcceptTypes,
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_KEEP_CONNECTION | dwHttpsFlags, NULL);
DWORD dwError = 0;
DWORD dwStatusCode = 0;
DWORD dwStatusSize = sizeof(dwStatusCode);
bool flAgain = true;
// solange senden und mit vom Server benötigten Informationen anreichern, bis
// der Request durchläuft
while(flAgain)
{
BOOL flSend = ::HttpSendRequest(hRequest, strHeaders,
(DWORD)strHeaders.GetLength(),
(void *)(LPCSTR)writeStream.m_str,
writeStream.m_str.GetLength());
::HttpQueryInfo(hRequest,
HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE,
&dwStatusCode, &dwStatusSize, NULL);
switch(dwStatusCode)
{
case HTTP_STATUS_OK:
flAgain = false;
break;
case HTTP_STATUS_DENIED:
case HTTP_STATUS_PROXY_AUTH_REQ:
{
HWND hwndTop = ::GetForegroundWindow();
dwError = ::InternetErrorDlg(hwndTop, hRequest,
ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
NULL);
flAgain = (dwError == ERROR_INTERNET_FORCE_RETRY);
break;
}
default:
...
}
}
Thanks a lot
Matthias Schmidt
--
Matthias Schmidt mailto:***@sdm.de
sd&m AG http://www.sdm.de
software design & management
Berliner Str. 76, 63065 Offenbach am Main, Germany
Phone +49 69 82901-251, Fax -200