我写了一个自动登陆的程序,但服务器上有检查使用程序登陆的机制,根据我对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进行提交呢?

解决方案 »

  1.   

    AnsiReplaceText(const AText, AFromText, AToText: string): string;接分。
      

  2.   

    找到Image的IHTMLElement接口之后用IHTMLElement.Click
      

  3.   

    楼上的还是没明白我的意思,我知道调用click可以提交页面,关键是这个方法提交的数据会同时把你在点击图片的相对坐标一起提交上去,而这个坐标如果是用鼠标提交的不会是(0,0),而调用Click方法绝对是(0,0),我无法修改这个坐标,修改了postdata数据后提交的还是(0,0),没修改过来
      

  4.   

    直接使用idHttp吧,想怎么控制都可以!