http OnPasswordRequest event
Return to Introduction  Previous page  Next page
Applies to
WinHTTP component.  

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

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  
    WinHTTP1.Username := UserPassForm.UsernameEdit.Text;  
    WinHTTP1.Password := UserPassForm.PasswordEdit.Text;  
    TryAgain := True; // Retry HTTP query (download attempt)  
  end;  
end;  



C++ Builder:

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

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