http OnPasswordRequest event
Return to Introduction  Previous page  Next page
Applies to
auHTTP and auAutoUpgrader components.  

Declaration
type  
  TauHTTPPasswordRequestEvent = procedure(Sender: TObject;  
     const Realm: Stringvar TryAgain: Boolean) of object;  
 
property OnPasswordRequest: TauHTTPPasswordRequestEvent;  

Description
The OnPasswordRequest event can be used to implement the dialog which asks user for his username and password to access the password protected Web area.  
 
Set TryAgain parameter to True to retry the HTTP query with correct username and password. (Don't forget to specify correct login information in this event handler to Username and Password properties.)  

Note
iiwarning If you leave this event unhandled (set TryAgain parameter to False), the component will generate error code #401 (Access Denied), which will be passed to OnHTTPError event.  

Example
Delphi:
procedure TForm1.HTTP1PasswordRequest(Sender: TObject;  
  const Realm: Stringvar TryAgain: Boolean);  
begin  
  { UserPassForm is any form with two edit boxes used for entering the login information (username and password) }  
  UserPassForm.RealmLabel := Realm;  
  if UserPassForm.ShowModal = ID_OK then  
  begin  
    auHTTP1.Username := UserPassForm.UsernameEdit.Text;  
    auHTTP1.Password := UserPassForm.PasswordEdit.Text;  
    TryAgain := True; // Retry HTTP query (download attempt)  
  end;  
end;  



C++ Builder:

void __fastcall TForm1::auHTTP1PasswordRequest(TObject *Sender,  
      AnsiString Realm, bool &TryAgain)  
{  
  UserPassForm->RealmLabel = Realm;  
  if (UserPassForm->ShowModal() == ID_OK)  
  {  
    auHTTP1->Username = UserPassForm->UsernameEdit->Text;  
    auHTTP1->Password = UserPassForm->PasswordEdit->Text;  
    TryAgain = True; // Retry HTTP query (download attempt)  
  };  
}  

See also
Username and Password properties; OnHTTPError event;  
HTTP Status Codes.  
File not found.