Don't use a TStringStream
at all. You are forcing UTF-8 decoding with it, but if the reply data is not UTF-8 encoded then reading the DataString
can fail to decode the data and return a blank string.
Use the version of TIdHTTP.Post()
that returns a String
and let Indy decode the data for you based on the reply's actual charset:
function PostData(const AURL: string; AParamList: TStrings): string;
var
_idHTTP: TIdHTTP;
begin
_idHTTP := TIdHTTP.Create(nil);
try
_idHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(_idHTTP);
Result := _idHTTP.Post(AURL, AParamList);
finally
FreeAndNil(_idHTTP);
end;
end;
Update: the screenshot you provided shows a GET request, not a POST request:
function GetData(const AURL: string): string;
var
_idHTTP: TIdHTTP;
begin
_idHTTP := TIdHTTP.Create(nil);
try
_idHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(_idHTTP);
Result := _idHTTP.Get(AURL);
finally
FreeAndNil(_idHTTP);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
_Reply: string;
begin
_Reply := GetData('https://eturundus.eu/samsung-pin-lt/_ajax/pin?id=276683492511635&pin=4580');
ShowMessage(_Reply);
end;