Solved

Auto Login to a asp webpage in my delphil app.

Posted on 2006-11-12
3
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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