如题

解决方案 »

  1.   

    检查一个URL是否有效
      这个函数将会检查URL是否有效。唯一的先决条件就是你必须在线。  URL前可能有 http:// 前缀,却省情况也是 http:// 作前缀,函数 internetOpenUrl 对 FTP:// 和 gopher:// 前缀均提供支持。    例子中我检查返回代码是否为 '200' 和 '302'(重定位标记),你也可以按你的需要修改返回码. 仅修改 the result := 表达式 这句即可.     uses wininet;     Function CheckUrl(url:string):boolean;   var   hSession, hfile, hRequest: hInternet;   dwindex,dwcodelen :dword;   dwcode:array[1..20] of char;   res : pchar;   begin   if pos('http://',lowercase(url))=0 then   url := 'http://'+url;   Result := false;   hSession := InternetOpen('InetURL:/1.0',   INTERNET_OPEN_TYPE_PRECONFIG,nil, nil, 0);   if assigned(hsession) then   begin   hfile := InternetOpenUrl(   hsession,   pchar(url),   nil,   0,   INTERNET_FLAG_RELOAD,   0);   dwIndex := 0;   dwCodeLen := 10;   HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE,   @dwcode, dwcodeLen, dwIndex);   res := pchar(@dwcode);   result:= (res ='200') or (res ='302');   if assigned(hfile) then   InternetCloseHandle(hfile);   InternetCloseHandle(hsession);   end;     end;   
      

  2.   

    呵呵,简单的办法,用winexec调用ping命令,然后分析返回的结果就可以了