Re: Delphi: Send Login and Password to URL


[ Delphi Forum -- by DelphiLand ]

Posted by webmaster Guido on December 04, 2003 at 16:19:46:

In Reply to: Re: Send Login and Password to URL posted by neo_aj on December 04, 2003 at 08:03:14:

: : : How do I sent a login string and password string from a link on a Menu Item?
: : ----------------------

: : Let's set up a form with 3 Edit boxes:

: : - edLogin: for the login;
: : - edPassword: for the password;
: : - edPage: for the address of the page (without the "http://" part).
: :
: : Additionally, there's a button to initiate the login, named btnLogin, and there's a label named lblReturn, to show if there was an error.

: : The code for the OnClick event of the button for accessing a password protected webpage is as follows:

: : procedure TForm1.btnLoginClick(Sender: TObject);
: : var
: : Login, Password, WebPage, LogText: string;
: : Return: integer;
: : begin
: : Login := edLogin.Text;
: : Password :=edPassword.Text;
: : WebPage := edPage.Text;
: : LogText := 'http://' + Login + ':' + Password + '@' + Webpage;
: : Return := ShellExecute(Handle, 'open', PChar(LogText), nil, nil, SW_SHOW);
: : // If Return > 32 then it's OK, otherwise there was an error
: : // For values of Return, see: API help, ShellExecute
: : if Return > 32 then
: : lblReturn.Caption := 'OK, done'
: : else
: : lblReturn.Caption := IntToStr(Return);
: : end;
: :
: : Example: to access http://www.test.com with the login "abc" and the password '123', you would enter this in the edit-boxes:

: : - edLogin: abc
: : - edPassword: 123
: : - edPage: www.test.com

: : NOTE: add "SHELLAPI" to the USES statement of the form, otherwise Delphi won't find the ShellExecute function.

-----------------------------

: i tried, but it didn't do anything. i have a login page return by asp. when i runing these code, it only open a ie without log me on

------------------------------

First try it manually, so enter the "LogText" in the address box of your browser,for example:
http://login:password@www.yooha.com/login.htm

If that doesn't give the correct result, it can't be done with the Delphi code that I described.


[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]