procedure TFrmUrlCommit.CommitUrlData(vRefererUrl,
vCommitData: 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: OleVariant;
aWBCommit: TWebBrowser;
begin
aWBCommit := TWebBrowser.Create(nil);
vHeaders := 'Content-Type: application/x-www-form-urlencoded' + #10#13#0;
vPostData := GetPostData(vCommitData);
vFlags := 31;
TVarData(vPostData).vType := varArray;
aWBCommit.Navigate2(vRefererUrl, vFlags, vFrame, vPostData, vHeaders);
FreeAndNil(aWBCommit);
end;
使用:
CommitUrlData('http://10.97.0.9:8080/user/register.jsp',
'username=0001&password=qqq');