unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ActiveX, OleServer;
type
TForm1 = class(TForm)
Edit2: TEdit;
Edit3: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// 把 Post Dtat (String) 转成 IE 所需要的格式 VarArray
function StringToPostData(const Value: string): OleVariant;
begin
Result := Unassigned;
if Value <> '' then
begin
Result := VarArrayCreate([0, Length(Value) - 1], varByte);
Move(Pointer(Value)^, VarArrayLock(Result)^, Length(Value));
VarArrayUnlock(Result);
end;
end;
// 示范如何使用操控 IE Post Data
procedure TForm1.Button1Click(Sender: TObject);
var
IE: TInternetExplorer;
vFlag, vFrame, vPost, vHeader: OleVariant;
begin
CoInitialize(nil);
IE := TInternetExplorer.Create(nil);
try
// 开启新的 IE 并显示
IE.Visible := true;
vFlag := navOpenInNewWindow;
// Post String, 请依需求修改, 以下是 Delphi K.Top Login 用的 :P
vPost := StringToPostData(Format('Method_Type=login&Name=%s&Password=%s',
[Edit2.Text, Edit3.Text]));
// Post 的资料是加在 Http-Header 后方[/red]
// 在 Http-Header 处要多加 Content-Type 做解释 (不需要修改)
vHeader := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
// 使用 Navigate 连接到所要的 URL, 请依需求修改
IE.Navigate('XXX', vFlag, vFrame, vPost,
vHeader);
finally
IE.Free;
CoUnInitialize;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ActiveX, OleServer;
type
TForm1 = class(TForm)
Edit2: TEdit;
Edit3: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// 把 Post Dtat (String) 转成 IE 所需要的格式 VarArray
function StringToPostData(const Value: string): OleVariant;
begin
Result := Unassigned;
if Value <> '' then
begin
Result := VarArrayCreate([0, Length(Value) - 1], varByte);
Move(Pointer(Value)^, VarArrayLock(Result)^, Length(Value));
VarArrayUnlock(Result);
end;
end;
// 示范如何使用操控 IE Post Data
procedure TForm1.Button1Click(Sender: TObject);
var
IE: TInternetExplorer;
vFlag, vFrame, vPost, vHeader: OleVariant;
begin
CoInitialize(nil);
IE := TInternetExplorer.Create(nil);
try
// 开启新的 IE 并显示
IE.Visible := true;
vFlag := navOpenInNewWindow;
// Post String, 请依需求修改, 以下是 Delphi K.Top Login 用的 :P
vPost := StringToPostData(Format('Method_Type=login&Name=%s&Password=%s',
[Edit2.Text, Edit3.Text]));
// Post 的资料是加在 Http-Header 后方[/red]
// 在 Http-Header 处要多加 Content-Type 做解释 (不需要修改)
vHeader := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
// 使用 Navigate 连接到所要的 URL, 请依需求修改
IE.Navigate('XXX', vFlag, vFrame, vPost,
vHeader);
finally
IE.Free;
CoUnInitialize;
end;
end;
end.