码迷,mamicode.com
首页 > Windows程序 > 详细

[Delphi]检查URL是否有效的函数

时间:2016-06-13 19:07:05      阅读:587      评论:0      收藏:0      [点我收藏+]

标签:

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;

[Delphi]检查URL是否有效的函数

标签:

原文地址:http://www.cnblogs.com/chonghai/p/5581402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!