Delphi获取https URL内容

  • 文章来源:LG工作室
  • 发布时间:2017-04-24 15:13:40
  • 责任编辑:lg2lg5
导读:{***函数名:GetHttpsHtml***函数说明:获取当前页面的Html源代码***参数:sPageURL:页面URL地址bState:成功状态***返回。
{
***函数名  : GetHttpsHtml
***函数说明: 获取当前页面的Html源代码
***参数    :
             sPageURL: 页面URL地址
             bState     : 成功状态
***返回值  : 返回成功状态(True表示成功,False表示失败)
}
function GetHttpsHtml(sPageURL: string; var bState: Boolean): string;
var
    sStream: TStringStream;
    hInt, hUrl: HINTERNET;
    Buffer: PChar;
    dwRead: Cardinal;
begin
    try
        sStream := TStringStream.Create('');
        try
            GetMem(Buffer, 65536);
            hInt := InternetOpen('Delphi', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
            dwRead := 0;
            hUrl := InternetOpenUrl(hInt, PChar(sPageURL), nil, 0, INTERNET_FLAG_RELOAD, 0);
            repeat
                InternetReadFile(hUrl, Buffer, 1000, dwRead);
                if dwRead <> 0 then
                    sStream.Write(Buffer^, dwRead);
            until dwRead = 0;
            InternetCloseHandle(hUrl);
            InternetCloseHandle(hInt);
            FreeMem(Buffer);

            bState := True;
            Result := sStream.DataString;
        finally
            sStream.Free;
        end;
    except
        on e:Exception do
        begin
            bState := False;
            Result := e.Message;
        end;
    end;
end;
关键词:Delphi获取httpsURL
建站套餐
联系我们
客户案例