• TWebBrowser组件在DELPHI中POST数据和取得网页源文件


    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, OleCtrls, SHDocVw;

    type
    TForm1 = class(TForm)
         WebBrowser1: TWebBrowser;
         Memo1: TMemo;
         Button1: TButton;
         procedure Button1Click(Sender: TObject);
    *******
         { Private declarations }
    public
         { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    URL:OleVariant;
    POST:OleVariant;
    target:OleVariant;
    flag:OleVariant;
    header:OleVariant;
    PostStr:String;
    PostLen,Index:Integer;
    begin
    URL:='http://port.fudan.edu.cn:58080/amserver/UI/Login?goto=http%3A%2F%2Fwww.urp.fudan.edu.cn%3A81%2Fepstar%2Frs%2Fpr%2Fgwkh%2Fdzgwkh%2Fgr_dzgwkh_index.jsp&gotoOnFail=http://www.urp.fudan.edu.cn/portal?.flag=fail';
    PostStr:='Login.Token1=04538&Login.Token2=*******&Submit=%B5%C7+%C2%BC';
    target:=NULL;
    flag:=0;
    PostLen := Length(PostStr);
    // 用构建 varByte 类型的 Variant array
    Post := VarArrayCreate([0, (PostLen - 1)], varByte);
    // 填充数据
    for Index := 0 to PostLen - 1 do
         Post[Index] := Ord(PostStr[Index + 1]);
    // 填补头部数据注意:application
    Header := 'Content-Type: application/x-www-form-urlencoded';

    WebBrowser1.Navigate2(URL,flag,target,POST,Header);
    while WebBrowser1.Busy=True do
          Application.ProcessMessages ;
    if WebBrowser1.ReadyState =READYSTATE_COMPLETE    then
    Memo1.Text :=WebBrowser1.OleObject.Document.all.tags('HTML').Item(0).outerHTML;
    else
    Memo1.Text:='页面加载失败';
    end;


    end.

  • 相关阅读:
    「笔记」高斯消元
    函数库
    数学公式杂记
    CF1290E Cartesian Tree
    洛谷 P4027 [NOI2007] 货币兑换
    审计ThinkCMF框架任意内容包含漏洞与复现
    PHP代码审计笔记(基础篇)--命令执行漏洞
    某校园缴费平台通用0day偶然发现之路
    【转】教育src挖掘经验
    近期学习文章的整理(超级干货总结分享)
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668570.html
Copyright © 2020-2023  润新知