procedure TFrmUrlCommit.CommitUrlData(vRefererUrl: OleVariant;
UserField, UserValue, PasswordField, PasswordValue: string;
OtherPostData: OleVariant);
// 内部小函数,把提交字符串写入variant;
function GetPostData(Content: string): OleVariant;
var
I: Integer;
begin
Result := VarArrayCreate([0, length(content)], varByte);
for i := 0 to Length(content) - 1 do
begin
Result := Ord(content[i + 1]);
end;
Result[Length(content)] := 0;
end;
// 内部小函数结束
var
vHeaders, vPostData, vFrame, vFlags, vCommitData: OleVariant;
aWBCommit: TWebBrowser;
begin
aWBCommit := TWebBrowser.Create(nil);
vHeaders := 'Content-Type: application/x-www-form-urlencoded' + #10#13#0;
if VarIsNull(OtherPostData) then
vCommitData := UserField + '=' + UserValue + '&' +
PasswordField + '=' + PasswordValue
else
vCommitData := UserField + '=' + UserValue + '&' +
PasswordField + '=' + PasswordValue + '&' + OtherPostData;
vPostData := GetPostData(vCommitData);
vFlags := 31;
TVarData(vPostData).vType := varArray;
aWBCommit.Navigate2(vRefererUrl, vFlags, vFrame, vPostData, vHeaders);
FreeAndNil(aWBCommit);
end;
如下方式调用
CommitUrlData(
'http://10.97.0.6/cgi-bin/login',
'LoginName', 'aaa@good.com.cn',
'Password', 'aaa',
NULL);
当然各个 提交参数 要自己 分析。