Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Retrieve credentials using InternetErrorDlg

$
0
0

I have basic authentication and tomcat/SSO enabled web server. First request to the server gives status code as 401(expected.) I prompt user for credentials using InternetErrorDlg function. Now I wish to retrieve the entered credentials.

Below is the code sample I have been using.

HINTERNET hOpenHandle,  hConnectHandle, hResourceHandle;
DWORD dwError, dwErrorCode, dwResult dwStatus,dwStatusSize;
HWND hwnd = GetDesktopWindow();

dwStatusSize = sizeof(dwStatus);

hOpenHandle = InternetOpen(TEXT("Sample"),INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

hConnectHandle = InternetConnect(hOpenHandle,TEXT("Server Name"), Port_Number,NULL,NULL, INTERNET_SERVICE_HTTP,0,0);

hResourceHandle = HttpOpenRequest(hConnectHandle, TEXT("GET"), TEXT("Actul URL goes here"), NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);

LPVOID lpszBuffer;

resend:

HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0);

HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL);

lpszBuffer = new WCHAR[1000/sizeof(WCHAR)];

dwError = InternetErrorDlg(hwnd, hResourceHandle, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,&lpszBuffer);

if (dwError == ERROR_INTERNET_FORCE_RETRY)
{
         goto resend;
}

CString strInput(TEXT(""));
strInput.Format(_T("%s"),lpszBuffer);

However I never get the credentials in strNewHeaders. Can someone please help me out as to where am I going wrong or what additional steps I need to follow to retrieve the credentials.

Sumeet Bhatia --- [India]


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>