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;

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-24
  • 2021-11-28
  • 2022-12-23
  • 2021-06-17
  • 2021-11-16
  • 2022-12-23
相关资源
相似解决方案