How to encode TIdBytes to Base64 string (not AnsiString) ?
ASocket.IOHandler.CheckForDataOnSource(5);
if not ASocket.Socket.InputBufferIsEmpty then
begin
ASocket.Socket.InputBuffer.ExtractToBytes(data);
// here I need to encode data to base64 string, how ? I don't need AnsiString!!
// var s:string;
s := EncodeBase64(data, Length(data)); // but it will be AnsiString :(
Or how to send AnsiString via AContext.Connection.Socket.Write() ?
Compiler saying Implicit string cast from ‘AnsiString’ to ‘string’
“data” variable contains UTF-8 data from website.
You can use Indy’s
TIdEncoderMIMEclass to encodeString,TStream, andTIdBytedata to base64 (andTIdDecoderMIMEto decode from base64 back toString,TStream, orTIdBytes), eg:As for sending
AnsiStringdata, Indy in D2009+ simply does not have anyTIdIOHandler.Write()overloads for handlingAnsiStringdata at all, onlyUnicodeStringdata. To send anAnsiStringas-is, you can either:1) copy the
AnsiStringinto aTIdBytesusingRawToBytes()and then callTIdIOHandler.Write(TIdBytes):2) copy the
AnsiStringdata into aTStreamand then callTIdIOHandler.Write(TStream):Or: