Пишу Http сервер на основе http сервера в Indy 10. Мне нужно нормально декодировать русский текст, который приходит в URL. Сам Indy декодирует в крякозябры.| Код | class function TIdURI.URLDecode(ASrc: string): string; var i: integer; ESC: string[2]; CharCode: integer; begin Result := ''; {Do not Localize} // S.G. 27/11/2002: Spaces is NOT to be encoded as "+". // S.G. 27/11/2002: "+" is a field separator in query parameter, space is... // S.G. 27/11/2002: well, a space // ASrc := StringReplace(ASrc, '+', ' ', [rfReplaceAll]); {do not localize} i := 1; while i <= Length(ASrc) do begin if ASrc[i] <> '%' then begin {do not localize} Result := Result + ASrc[i] end else begin Inc(i); // skip the % char ESC := Copy(ASrc, i, 2); // Copy the escape code Inc(i, 1); // Then skip it. try CharCode := StrToInt('$' + ESC); {do not localize} Result := Result + Char(CharCode); except end; end; Inc(i); end; end;
|
|