Solved

Auto Login to a asp webpage in my delphil app.

Posted on 2006-11-12
3
347 Views
Last Modified: 2010-04-05
Hi all i have a project i am working on that logs into email account and checks email. I am looking for a solution the can login to a asp webpage it has a form username and password.. I am useing a Twebbrowser to load the url. I want to laod my username and password in the asp form in my Twebbrowser and auto login. See link below.
http://mail.grantfullen.com/
username: test@grantfullen.com
pass: test
0
Comment
Question by:Grant Fullen
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 17925918
there are 3 login examples here: http://www.ciuly.com/delphi/indy/index.html
the basic idea is the same for all demos so you should be able to adapt the one that suits your purpose better to your site.
of course this is using indy and not twebbrowser.

if you do want to use twebbrowser for this (though I can't see why), you will do something like:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls, mshtml;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
  private
    { Private declarations }
  loginForm: IHTMLFormElement;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Navigate('http://mail.grantfullen.com/');
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  htmlDoc: IHTMLDocument2;
  allForms: IHTMLElementCollection;
  field: IHTMLElement;
  inputField: IHTMLInputElement;
  a,u :olevariant;
begin
  if url<>'http://mail.grantfullen.com/' then
    exit;
  htmlDoc := WebBrowser1.Document as IHTMLDocument2;
  allForms := htmlDoc.Forms;
  loginForm := allForms.Item('Login','') as IHTMLFormElement;
  field := loginForm.Item('txtUserName','') as IHTMLElement;
  if assigned(field) then
  begin
    inputField := field as IHTMLInputElement;
    inputField.value := 'test@grantfullen.com';
  end;
  field := loginForm.Item('txtPassword','') as IHTMLElement;
  if assigned(field) then
  begin
    inputField := field as IHTMLInputElement;
    inputField.value := 'test';
  end;
  a:=WebBrowser1.OleObject.document.all.tags('a').item(0);
  u:=a.href;
  WebBrowser1.Navigate2(u);
end;

end.





dfm follows:


object Form1: TForm1
  Left = 192
  Top = 125
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object WebBrowser1: TWebBrowser
    Left = 0
    Top = 48
    Width = 688
    Height = 398
    TabOrder = 0
    OnDocumentComplete = WebBrowser1DocumentComplete
    ControlData = {
      4C0000001B470000222900000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
end


for more info about twebbrowser and ole automation, see http://www.cryer.co.uk/brian/delphi/twebbrowser/twebbrowser_oleobject.htm
you might also consider moving to TEmbeddedWB: http://www.bsalsa.com/product.html
0
 

Author Comment

by:Grant Fullen
ID: 17926193
I like the PersistentConnection example but not working well . Invaled Date Code.. Bit it seems simlar to what i will need.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17926575
so ... did you get it to work or still need help?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 314
Path  to current project in Delphi. 2 90
add combobox item based on numbers 9 154
Downloading email attachments 2 79
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question