WebBrowser使用POST方法提交数据

WebBrowser使用POST方法提交数据.

 

unit Unit1; 

interface 

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

type 
TForm1 = class(TForm) 
    WebBrowser1: TWebBrowser; 
    Memo1: TMemo; 
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject); 
    { Private declarations }
public 
    { Public declarations } 
end; 

var 
Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject); 
var 
URL:OleVariant; 
POST:OleVariant; 
target:OleVariant; 
flag:OleVariant; 
header:OleVariant; 
PostStr:String; 
PostLen,Index:Integer; 
begin
  URL:=edit1.text;
  target:=NULL;
  flag:=0;
  PostStr:='ID1=111&ID2=222';
  PostLen := Length(PostStr);
  // 用构建 varByte 类型的 Variant array
  Post := VarArrayCreate([0, (PostLen - 1)], varByte);
  // 填充数据
  for Index := 0 to PostLen - 1 do
      Post[Index] := Ord(PostStr[Index + 1]);

  // 填补头部数据注意:application
  Header := 'Content-Type: application/x-www-form-urlencoded';

  WebBrowser1.Navigate2(URL,flag,target,POST,Header);
  while WebBrowser1.Busy=True do
       Application.ProcessMessages ;
  if WebBrowser1.ReadyState =READYSTATE_COMPLETE   then
  Memo1.Text :=WebBrowser1.OleObject.Document.all.tags('HTML').Item(0).outerHTML
  else
  Memo1.Text:='页面加载失败';
end;



end.


 

 

你可能感兴趣的:(Web编程,delphi开发)