程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 更多關於編程 >> Delphi完成斷定網址能否存在及能否可以翻開的辦法

Delphi完成斷定網址能否存在及能否可以翻開的辦法

編輯:更多關於編程

Delphi完成斷定網址能否存在及能否可以翻開的辦法。本站提示廣大學習愛好者:(Delphi完成斷定網址能否存在及能否可以翻開的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成斷定網址能否存在及能否可以翻開的辦法正文


本例所述Delphi法式用於檢測網址能否為404,也就是檢測網址能否存在,或能否可以翻開,針對分歧的檢討辦法,會前往分歧的成果。

法式重要代碼以下:

unit address;
interface
uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 Psock, NMHttp, StdCtrls, ComCtrls;
type
 TForm1 = class(TForm)
  Label1: TLabel;
  Edit1: TEdit;
  Button1: TButton;
  NMHTTP1: TNMHTTP;
  StatusBar1: TStatusBar;
  procedure Button1Click(Sender: TObject);
  procedure NMHTTP1Success(Cmd: CmdType);
  procedure NMHTTP1Failure(Cmd: CmdType);
  procedure NMHTTP1HostResolved(Sender: TComponent);
  procedure NMHTTP1InvalidHost(var Handled: Boolean);
  procedure NMHTTP1AuthenticationNeeded(Sender: TObject);
  procedure NMHTTP1Connect(Sender: TObject);
  procedure NMHTTP1ConnectionFailed(Sender: TObject);
  procedure FormActivate(Sender: TObject);
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure NMHTTP1Redirect(var Handled: Boolean);
  procedure Edit1KeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
 private
  { Private declarations }
 public
  { Public declarations }
 end;
var
 Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
 url:string;
begin
 url:=Edit1.Text;
 StatusBar1.simpletext:='正在磨練';
 NMHTTP1.Head(url);
end;
procedure TForm1.NMHTTP1Success(Cmd: CmdType);
begin
 case cmd of
 CmdHEAD:
  StatusBar1.SimpleText:='網址准確'
 end;
end;
procedure TForm1.NMHTTP1Failure(Cmd: CmdType);
begin
 case cmd of
 CmdHEAD:
  StatusBar1.SimpleText:='網址不准確,沒有這個頁面'
 end;
end;
procedure TForm1.NMHTTP1HostResolved(Sender: TComponent);
begin
 StatusBar1.SimpleText:='准確解析主機名';
end;
procedure TForm1.NMHTTP1InvalidHost(var Handled: Boolean);
begin
 StatusBar1.SimpleText:='不克不及解析主機名';
end;
procedure TForm1.NMHTTP1AuthenticationNeeded(Sender: TObject);
begin
 StatusBar1.SimpleText:='須要身份驗證';
end;
procedure TForm1.NMHTTP1Connect(Sender: TObject);
begin
 StatusBar1.SimpleText:='銜接到主機';
end;
procedure TForm1.NMHTTP1ConnectionFailed(Sender: TObject);
begin
 StatusBar1.SimpleText:='銜接主機掉敗';
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
 Edit1.Text:='http://www.';
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 NMHTTP1.Destroy;
end;
procedure TForm1.NMHTTP1Redirect(var Handled: Boolean);
begin
 StatusBar1.SimpleText:='重定向到其它頁面';
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
 Shift: TShiftState);
begin
 if Key=VK_RETURN then
 begin
  StatusBar1.simpletext:='正在磨練';
  NMHTTP1.Head(Edit1.Text);
 end;
end;
end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved