改了一个,不敢独享。
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.10.1.1/sys_user/logined.jsp',
'user_name', 'test',
'user_pass', 'test',
'Submit=%CC%E1%BD%BB');