⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubutils.pas

📁 本代码是展示了如何通过delphi监控指定web站点的运行情况
💻 PAS
字号:
unit PubUtils;

interface

uses
  Windows, SysUtils, Classes, WinInet, IcsUrl;

procedure GetProxySetup(Protocol: string; var Host: string; var Port: string);
function ParamsEncode(Params: TStrings): string;

implementation

function ParamsEncode(Params: TStrings): string;
var
  S: string;
  i: Integer;
begin
  for i := 0 to Params.Count - 1  do
  begin
    S := Params[i];
    Params[i] := Copy(S, 1, Pos('=', S));
    Delete(S, 1, Pos('=', S));
    Params[i] := Params[i] + UrlEncode(S);
  end;

  Result := Params.CommaText;
  Result := StringReplace(Result, ',', '&', [rfReplaceAll]);
end;

function GetProxyInformation: string;
var
  Info: PInternetProxyInfo;
  Len: DWORD;
begin
  Result := '';
  Len := 4096;
  GetMem(Info, Len);
  try
    if InternetQueryOption(nil, INTERNET_OPTION_PROXY, Info, Len) then
      if Info^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
        Result := Info^.lpszProxy;
  finally
    FreeMem(Info);
  end;
end;

procedure GetProxySetup(Protocol: string; var Host: string; var Port: string);
var
  i: Integer;
  Info: string;
begin
  Host := '';
  Port := '';

  Info := GetProxyInformation;
  if Info = '' then Exit;

  Protocol := Protocol + '=';
  i := Pos(Protocol, Info);
  if i > 0 then
  begin
    Delete(Info, 1, i + Length(Protocol));
    i := Pos(':', Host);
    if i > 0  then
      Info := Copy(Info, 1, i - 1);
  end;

  i := Pos(':', Info);
  if i > 0 then
  begin
    Port := Copy(Info, i + 1, Length(Info) - i);
    Host := Copy(Info, 1, i - 1);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -