url提交参数类

url提交参数类

type
  /// <summary>
  /// 准备url
  /// </summary>
  TynUrl = class
  private
    FUrl, FCommand: string;
    FParams: TStringList;
    function GetText: string;
  public
    constructor Create;
    destructor Destroy; override;
    property url: string read FUrl write FUrl;
    property command: string read FCommand write FCommand;
    property params: TStringList read FParams write FParams;
    property text: string read GetText;
  end;

  

{ TynUrl }

constructor TynUrl.Create;
begin
  FParams := TStringList.Create;
end;

destructor TynUrl.Destroy;
begin
  FreeAndNil(FParams);
  inherited;
end;

function TynUrl.GetText: string;
var
  i: Integer;
  s: string;
begin
  Result := FUrl + '/' + FCommand;
  for i:=0 to FParams.Count -1 do
  begin
    if i = 0 then
      s := s + FParams.Names[i] + '=' + TNetEncoding.URL.Encode(FParams.ValueFromIndex[i])
    else
      s := s + '&' + FParams.Names[i] + '=' + TNetEncoding.URL.Encode(FParams.ValueFromIndex[i]);
  end;
  Result := Result + '?' + s;
end;

  

posted @ 2019-03-10 16:40  delphi中间件  阅读(658)  评论(0编辑  收藏  举报