1. 程式人生 > >Delphi idHttpServer接收Http Get請求解碼問題

Delphi idHttpServer接收Http Get請求解碼問題

ssa message var try -m 接口 ons main text

引用 Httpapp單元,
使用Httpdecode函數進行解碼

procedure TFrmMain.HTTPServerCommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  RespStr,recvText: string;
  msgText: string;
begin
  CoInitialize(nil);
  try
    try
      msgText := Log|【+FormatDateTime(
yyyy-mm-dd hh:mm:ss,Now)++Format(收到請求:類型:%s, 路徑:%s,來自:%s:%d, [ARequestInfo.Command, ARequestInfo.Document, TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerIP, TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerPort]); SendMessage(FrmMain.Handle,MYTHREAD_MESSAGE,Integer(@msgText),
1); if ARequestInfo.Command = GET then recvText := Utf8ToAnsi(Httpdecode(ARequestInfo.QueryParams)) //引用 Httpapp else if ARequestInfo.Command = POST then//post recvText := Utf8ToAnsi(ARequestInfo.FormParams); if (Pos(LowerCase(/api/getBusinessHallStatus), LowerCase(ARequestInfo.Document)) = 1
) then //查詢營業廳狀態接口 begin RespStr := Httpserver_getBusinessHallStatus(recvText); end begin RespStr := URL路徑未定義; end; AResponseInfo.ContentType := text/HTML;charset=utf-8; AResponseInfo.ContentText := AnsiToUtf8(RespStr);except on e: Exception do begin msgText := ErrorLog|【+FormatDateTime(yyyy-mm-dd hh:mm:ss,Now)+】執行HTTPServerCommandGet發生異常,原因::+e.Message; SendMessage(FrmMain.Handle,MYTHREAD_MESSAGE,Integer(@msgText),1); end; end; finally CoUninitialize; end; end;

Delphi idHttpServer接收Http Get請求解碼問題