我写了一个自动登陆的程序,但服务器上有检查使用程序登陆的机制,根据我对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;//点击坐标
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
AnsiReplaceText(PostStr,'.x=0','.x='+inttostr(Rx));
AnsiReplaceText(PostStr,'.y=0','.y='+inttostr(Ry));
end;
showmessage(PostStr);
end;
end;
以上代码的AnsiReplaceText没有替换成功字符,而通过上面对postdata的处理,结果会把post上去的数据的&分割符号都去掉.还有如何把修改后的数据重新封到OleVariant进行提交呢?
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;//点击坐标
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
AnsiReplaceText(PostStr,'.x=0','.x='+inttostr(Rx));
AnsiReplaceText(PostStr,'.y=0','.y='+inttostr(Ry));
end;
showmessage(PostStr);
end;
end;
以上代码的AnsiReplaceText没有替换成功字符,而通过上面对postdata的处理,结果会把post上去的数据的&分割符号都去掉.还有如何把修改后的数据重新封到OleVariant进行提交呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货