delphi 解析

//delphi7
use IdStrings,HTTPApp;

/// <summary>
/// 解析http 格式数据 application/x-www-form-urlencoded
/// </summary>
function ParseHttpFormData(const AFormData: string): TStringList;
var
  DecodedData: string;
begin
  DecodedData := HTTPDecode(AFormData);
 //解析参数
  Result := TStringList.Create;
 //用idstring 来解析 D7版本有空格的话。会解析有问题
  SplitColumns(DecodedData, Result, '&');
end;

//如果有RTC的话   use rtcInfo
function ParseHttpFormDataForRTC(const AFormData: string): TRtcHttpValues;
begin
 Result := TRtcHttpValues.Create;
 //进来的如果有urlencode 就得decode
 Result.Text := URL_Decode(AFormData);
 //取值 Result.asString['name'];
end;

//高版本
//use System.NetEncoding
function ParseHttpFormData(const AFormData: string): TStringList;
var
  DecodedData: string;
begin
  // URL解码
  DecodedData := TNetEncoding.URL.Decode(AFormData);
  // 解析参数
  Result := TStringList.Create;
  Result.Delimiter := '&';
  Result.StrictDelimiter := True;
  Result.DelimitedText := DecodedData;
  //取值 Result.Values['serviceType']
end;

 

posted @ 2025-11-26 16:50  Tag  阅读(0)  评论(0)    收藏  举报