Solved

Auto Login to a asp webpage in my delphil app.

Posted on 2006-11-12
3
344 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:
ciuly earned 500 total points
Comment Utility
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
Comment Utility
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:ciuly
Comment Utility
so ... did you get it to work or still need help?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now