Discussion:
WININET NTLM and default credentials for current user
(too old to reply)
Matthias Schmidt
2005-06-15 12:53:01 UTC
Permalink
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
Reymarx Gereda
2005-06-15 19:22:08 UTC
Permalink
You can try providing your credentials in the InternetConnect call (4th and
5th parameter).

Otherwiwse, you can try with InternetSetOption using the
INTERNET_OPTION_USERNAME and INTERNET_OPTION_PASSWORD flags.
--
Reymarx [MSFT]
Windows- Networking
This posting is provided "AS IS" with no warranties, and confers no rights
Post by Matthias Schmidt
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.
HINTERNET hInternet = NULL;
HINTERNET hConnection = NULL;
HINTERNET hRequest = NULL;
hInternet = ::InternetOpen("SOAPCLIENT",
strProxy.GetLength() ?
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)
{
flAgain = false;
break;
{
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;
}
...
}
}
Thanks a lot
Matthias Schmidt
--
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
Matthias Schmidt
2005-06-16 17:11:07 UTC
Permalink
silly me. Its just a problem with the internet settings. If the called url is
configured as a trusted server then all just works!

ciao
matthias
Post by Reymarx Gereda
You can try providing your credentials in the InternetConnect call (4th and
5th parameter).
Otherwiwse, you can try with InternetSetOption using the
INTERNET_OPTION_USERNAME and INTERNET_OPTION_PASSWORD flags.
--
Reymarx [MSFT]
Windows- Networking
This posting is provided "AS IS" with no warranties, and confers no rights
Post by Matthias Schmidt
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.
HINTERNET hInternet = NULL;
HINTERNET hConnection = NULL;
HINTERNET hRequest = NULL;
hInternet = ::InternetOpen("SOAPCLIENT",
strProxy.GetLength() ?
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)
{
flAgain = false;
break;
{
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;
}
...
}
}
Thanks a lot
Matthias Schmidt
--
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
y***@gmail.com
2005-07-08 13:19:23 UTC
Permalink
i have created a live update for my application. My clients need to run
run the live update behind a proxy. How can i using WinInet API
authenticate aganist this proxy so that i can reach the live update?
Loading...