您的位置:首页 > 理论基础 > 计算机网络

Delphi 用idhttp 获取网页源码

2016-04-08 12:18 561 查看
unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs,IdHTTP, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

function GetWebPage(const Url :string; IsUtf8 :Boolean = False):string;

var

idp :TIdHTTP;

begin

Result := '';

idp := TIdHTTP.Create(Application);

try

idp.HandleRedirects := True;

idp.Request.UserAgent := 'Mozilla/5.0';

Result := idp.Get(Url);

if IsUtf8 then

Result := Utf8ToAnsi(Result);

finally

FreeAndNil(idp);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

ShowMessage(GetWebPage('http://lede100.wicp.net:9600/lede/index.php/Dati/Index/Index.html',true));

end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: