F
fingerwin
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个自动登陆的程序,但服务器上有检查使用程序登陆的机制,根据我对http抓包分析.他们的检查是应该是通过提交代码的Onbeforepaste事件把鼠标点击的坐标一起提交,因为我的程序里直接使用了olevariant的click方法,所以提交上去的坐标都是(0,0),所以我需要在BeforeNavigate2里对postdata进行修改.
procedure TFrm_Main.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
iLoop:Integer;
PostStr:String;
x,y:Integer;//点击坐标
newpost:OleVariant;
Rx,Ry:Integer;
begin
Randomize;
Rx:=Random(73);
Ry:=Random(23);
PostStr:='';
x:=-1;
y:=-1;
if Length(PostData)> 0 then
begin
for iLoop:=0 to VarArrayHighBound(PostData,1) do
begin
PostStr:=PostStr+Chr(Byte(PostData[iLoop]));
end;
if (Pos('.x=',PostStr)> 0) and (Pos('.y=',PostStr)> 0) then
begin
PostStr:=AnsiReplaceText(PostStr,'.x=0','.x='+inttostr(Rx));
PostStr:=AnsiReplaceText(PostStr,'.y=0','.y='+inttostr(Ry));
end;
newpost := VarArrayCreate([0, (Length(PostStr) - 1)], varByte);
// 填充数据
for iLoop := 0 to Length(PostStr) - 1 do
newpost[iLoop] := Ord(PostStr[iLoop + 1]);
PostData:= newpost;
//showmessage(PostStr);
end;
end;
通过以上代码修改postdata成功,并且再转过来显示已经修改的数据,但通过对http抓包post数据,还是提交的原来的数据.
procedure TFrm_Main.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
iLoop:Integer;
PostStr:String;
x,y:Integer;//点击坐标
newpost:OleVariant;
Rx,Ry:Integer;
begin
Randomize;
Rx:=Random(73);
Ry:=Random(23);
PostStr:='';
x:=-1;
y:=-1;
if Length(PostData)> 0 then
begin
for iLoop:=0 to VarArrayHighBound(PostData,1) do
begin
PostStr:=PostStr+Chr(Byte(PostData[iLoop]));
end;
if (Pos('.x=',PostStr)> 0) and (Pos('.y=',PostStr)> 0) then
begin
PostStr:=AnsiReplaceText(PostStr,'.x=0','.x='+inttostr(Rx));
PostStr:=AnsiReplaceText(PostStr,'.y=0','.y='+inttostr(Ry));
end;
newpost := VarArrayCreate([0, (Length(PostStr) - 1)], varByte);
// 填充数据
for iLoop := 0 to Length(PostStr) - 1 do
newpost[iLoop] := Ord(PostStr[iLoop + 1]);
PostData:= newpost;
//showmessage(PostStr);
end;
end;
通过以上代码修改postdata成功,并且再转过来显示已经修改的数据,但通过对http抓包post数据,还是提交的原来的数据.