Article ID: 189094
Article Last Modified on 12/2/2003
if (dwRet == HTTP_STATUS_DENIED)
{
DWORD dwPrompt;
//dwPrompt = pFile->ErrorDlg(NULL,
//ERROR_INTERNET_INCORRECT_PASSWORD,
//FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
//FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
LPVOID lpEmpty;
dwPrompt = ::InternetErrorDlg(GetDesktopWindow(), *pFile,
ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
| FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
&lpEmpty);
if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)
...
In some cases, you may want different parameters for InternetErrorDlg. See
the WinInet documentation for InternetErrorDlg and the MFC source code for
CHttpFile::ErrorDlg. Note that you must change your project setting to link
with wininet.lib in order to use InternetErrorDlg.
if (dwRet == HTTP_STATUS_DENIED)
{
cerr << "This page is password protected. " << endl;
CHAR szUser[50]="";
CHAR szPass[50]="";
cerr << "User: "; cin >> szUser;
// This should really not show the password on the screen.
cerr << "Pass: "; cin >> szPass;
// You have to read all outstanding data on the Internet handle
// before you can resubmit the request. Just discard the data.
CString strBuff;
while (pFile->ReadString(strBuff))
{
}
pServer->SetOption(INTERNET_OPTION_USERNAME, szUser,
lstrlen(szUser));
pServer->SetOption(INTERNET_OPTION_PASSWORD, szPass,
lstrlen(szPass));
pFile->SendRequest();
...
Notice that SetOption is being called on the CHttpConnection per the
InternetSetOption documentation in Visual C++ which states the following:
Sets the user name associated with a handle returned by InternetConnect.
Additional query words: InternetErrorDlg ErrorDlg CHttpFile
Keywords: kbbug kbfix kbvc600fix KB189094