Solved

Auto Login to a asp webpage in my delphil app.

Posted on 2006-11-12
3
351 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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