哪种post方法最简单?(讨论一下)(50分)

  • 主题发起人 主题发起人 chenboby
  • 开始时间 开始时间
C

chenboby

Unregistered / Unconfirmed
GUEST, unregistred user!
我比较喜欢用Webbrowser,总觉得用Http比较不稳定。大家觉得呢?
 
曾经见过这样的程序段:
unit MainFrm;
{
自动登陆网站示例代码
模拟提交网页表单数据
by aaww - aaww@yeah.net
射雕工作室提供技术支持
All code is provided as is
http://aaww.yeah.net
}

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
lblFlavor: TLabel;
edtFirstName: TEdit;
btnSubmit: TButton;
cmbxFlavor: TComboBox;
WebBrowser1: TWebBrowser;
procedure btnSubmitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses HTTPApp;

{$R *.DFM}

procedure TForm1.btnSubmitClick(Sender: TObject);
var
EncodedDataString: string;
PostData: OleVariant;
Headers: OleVariant;
I: Integer;
begin
// First, create a URL encoded string of the data
EncodedDataString := 'username=' + HTTPEncode(edtFirstName.Text) + '&' +
'password=' + HttpEncode(cmbxFlavor.Text);
// The PostData OleVariant needs to be an array of bytes as large
// as the string (minus the NULL terminator)
PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);
// Now, move the Ordinal value of the character into the PostData array
for I := 1 to Length(EncodedDataString) do
PostData[I-1] := Ord(EncodedDataString);
Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
// Finally, we just Naviagte to the URL. Note that you may have to modify
// the path to your ASP page's location.
WebBrowser1.Navigate('http://www.xxx.net/login.asp', EmptyParam,EmptyParam, PostData, Headers);
end;
end.
可是编译的时候却说VarArrayCreate没有定义,可我看帮助这却是个已定义过的函数,百思不得其解,有人能告诉我为什么吗?
 
kouchun只要post,用不着动用XML吧!
 
没人讨论一下吗?
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部