如何测定一个URL是否存在?在线等待。(20分)

F

fxrm411

Unregistered / Unconfirmed
GUEST, unregistred user!
如何测定一个URL是否存在?在线等待。大家快帮忙
 
用indy控件,我县测试的,没问题
unit Main;

interface

uses
Windows, Messages, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
SysUtils, Classes, IdIcmpClient, IdBaseComponent, IdComponent, IdRawBase, IdRawClient;


type
TfrmPing = class(TForm)
lstReplies: TListBox;
ICMP: TIdIcmpClient;
Panel1: TPanel;
btnPing: TButton;
edtHost: TEdit;
procedure btnPingClick(Sender: TObject);
procedure ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
private
public
end;

var
frmPing: TfrmPing;

implementation
{$R *.DFM}

procedure TfrmPing.btnPingClick(Sender: TObject);
var
i: integer;
begin

ICMP.OnReply := ICMPReply;
ICMP.ReceiveTimeout := 1000;
btnPing.Enabled := False; try
ICMP.Host := edtHost.Text;
for i := 1 to 4 do begin
ICMP.Ping;
Application.ProcessMessages;
//Sleep(1000);
end;
except on E: Exception do begin
showMessage('url不存在');
btnPing.Enabled := True;
end;
end;
btnPing.Enabled := True;
end;

procedure TfrmPing.ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
var
sTime: string;
begin
// TODO: check for error on ping reply (ReplyStatus.MsgType?)
if (ReplyStatus.MsRoundTripTime = 0) then
sTime := '<1'
else
sTime := '=';

lstReplies.Items.Add(Format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',
[ReplyStatus.BytesReceived,
ReplyStatus.FromIpAddress,
ReplyStatus.SequenceId,
ReplyStatus.TimeToLive,
sTime,
ReplyStatus.MsRoundTripTime]));
end;

end.
 
我刚才回的那个主题怎么被删除了?

try
IdHTTP1.Head('http://somesite.com/somepage.htm');
if pos('200 OK', IdHTTP1.Response.ResponseText) <> -1 then
showmessage('网页存在')
else
showmessage('网页不存在');
except
showmessage('网页不存在');
end;
 
feifeich 你的代码运行有这样的提示,是怎么回事?
project project1.exe raised exception class eidsocketerror with message 'socket error 11001'.process stopped .use step or run to continue.
 
是访问一个不存在的页面么,这是会有异常的,不过我的代码里捕获了呀。我在Delphi7里调试正常。
 
顶部