fphttpclient: encoding problems in Get(), Post() etc. that use TStringStream
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Due to changes in TStringStream http://wiki.freepascal.org/User_Changes_Trunk#TStringStream_now_observe_system_encoding
all methods in fphttpclient that internally use TStringStream assume Delphi=ANSI codepage. E.g.:
function TFPCustomHTTPClient.Post(const URL: string): String;
Var
SS : TStringStream;
begin
SS:=TStringStream.Create('');
try
Post(URL,SS);
Result:=SS.Datastring;
finally
SS.Free;
end;
end;
This effectively prohibits the use of these methods on Windows because TEncoding.Default is always ANSI on Windows but almost no responses are encoded in ANSI.
Additional information:
I suggest the 2 possible fixes:
1.) Add TFPCustomHTTPClient.DefaultEncoding property.
2.) Read the response encoding from the "Content-Type" header automatically.
3.) If encoding information is found in the Content-Type header, use it. Otherwise use the DefaultEncoding for the string conversion.
-- OR --
Return RawByteString from these methods with no encoding changes from TStringStream.
Mantis conversion info:
- Mantis ID: 35306
- Fixed in version: 3.3.1
- Fixed in revision: 42875 (#def80285)
- Target version: 3.2.0