大家好:
    请教一下,现在做一个工具,向网页发包。而网页向服务器发的内容是经过网页前台加密的,服务器发过来的包也是加密,经过网页前台解密再显示的,网页源码里能看到加密和解密的函数,那我要向服务器发包的话,应该也是要加密。问题是delphi里能不能调用网页的加密/解密函数,这个应该怎样去调啊?并且函数名可能要通过字符串来传达,例如这个网:http://www.qianxibei.com/member/index.html 

解决方案 »

  1.   

    既然能看到加密和解密的代码,那么就把这代码转成delphi代码,直接调用代码估计是不可能的
      

  2.   

    http://www.winu.cn/space-14160-do-blog-id-2731.html
    How to call JavaScript functions in a TWebBrowser from Delphi 如何用Delphi在TWebBrowser中调用JavaScript
    Rewritten by tamsun
    Source From delphidabbler.com   
     
     
     
     方法介绍   
     
     在TWebBrowser中调用脚本的办法是调用Html文档相关的对象窗口中的execScript方法。至于什么是和Html Document相关的对象窗口,后面的代码中用到的IHTMLWindow2就是。execScript函数定义如下: function execScript(const code: WideString; const language: WideString): OleVariant;参数code是一个脚本函数的完整调用形式的字符串,例如有一个JavaScript函数定义为:
    function foo(param1),则 code="foo(param1)"。
    参数language表示脚本的类型,例如 language="JavaScript" 
    首先,获取浏览器组件的文档对象;然后通过该文档对象的ParentWindow属性来获取窗口对象。最后通过该窗口对象来调用execScript即可。下面就给出一个简单的实现示例。   
     
     
     
     实现示例   
     
     
    uses
      MSHTML;
      
    procedure TForm1.CallFoo(S: string; I: Integer);
      { Calls JavaScript Foo() function }
    var
      Doc: IHTMLDocument2;      // current HTML document
      HTMLWindow: IHTMLWindow2; // parent window of current HTML document
      JSFn: string;             // stores JavaScipt function call
    begin
      // Get reference to current document
      Doc := WebBrowser1.Document as IHTMLDocument2;
      if not Assigned(Doc) then
        Exit;
      // Get parent window of current document
      HTMLWindow := Doc.parentWindow;
      if not Assigned(HTMLWindow) then
        Exit;
      // Run JavaScript
      try
        JSFn := Format('Foo(''%s'',%d)', [S, I]);  // build function call
        HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
      except
        // handle exception in case JavaScript fails to run
      end;
    end;  
     
     
     
     实例演示   
     
     整个实例包括两部分: 网页文件test.html:文件内有一个JavaScript函数SetFont。该函数通过下拉框来选择字体,然后点击”set font“按钮来改变页面字体。 
    Delphi端程序:通过TWebbrowser来显示页面,并演示如何调用页面内的Javascript函数。   
     
     Test.html: 
    <html>
    <head>
    <title> Demo for call Javascript from Delphi 
    </title>
    <script type="text/javascript">
    <!--
    function SetFont(fontname)
    {
        document.body.style.fontFamily = fontname; 
    }
    -->
    </script>
    </head><body>
    demo of calling Javascript from Delphi
    <form>
    <select size=1 name="selfont">
    <option value="Verdana" selected>Verdana</option>
    <option value="Arial">Arial</option>
    <option value="Courier New">Courier New</option>
    <option value="Tahoma">Tahoma</option>
    </select>
    <input type="button" value="set font" name="btn1" 
       onclick="SetFont(selfont.value)">
    </form>
    </body>
    </html>
      
     
     Delphi控制Javascript uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleCtrls, SHDocVw, StdCtrls, Mshtml;type
      TForm1 = class(TForm)
        btnCallJS: TButton;
        cmbFonts: TComboBox;
        WebNav: TWebBrowser;
        procedure FormShow(Sender: TObject);
        procedure WebNavDocumentComplete(Sender: TObject;
          const pDisp: IDispatch; var URL: OleVariant);
        procedure btnCallJSClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);
    begin
      // Disable button
      btnCallJS.Enabled := false;
      // Load the Html page
      WebNav.Navigate(ExtractFilepath(Application.ExeName)
          +'test.html');
    end;procedure TForm1.WebNavDocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    begin
      // When complete loading Html page, enable button
      btnCallJS.Enabled := true;
    end;// Call the Javascript in Html page
    procedure TForm1.btnCallJSClick(Sender: TObject);
    var
      // current Html document
      Doc : IHtmlDocument2;
      // parent window of current Html document
      HtmlWnd : IHtmlWindow2;
      // Javascript function name including arguments
      JsFnc : string;
    begin
      // Get reference to current document
      Doc := WebNav.Document as IHtmlDocument2;
      if not assigned(Doc) then
        exit;
      // Get parent window of current Html document
      HtmlWnd := Doc.parentWindow;
      if not assigned(HtmlWnd) then
        exit;
      // Run Javascript
      try
        JsFnc := 'SetFont(''' + trim(cmbFonts.Text) + ''')';
        HtmlWnd.execScript(JsFnc, 'JavaScript');
      except
        Showmessage('Call JavaScript failed!');
      end;
    end;end.
      

  3.   

    不用TWebBrowser的话,还有没有其它的方法啊?
      

  4.   

    我是不想用TWebBrowser控件,这个还要打开网站,能不能不打开页面,直接取呢
      

  5.   

    没有更好的方法啦吗?hunter103兄弟,打开网页很慢