I notice I have invalid characters for XML files in an application who use Indy Client (I actually use default parameters for IdHttp)
Here is my code :
ts := TStringList.Create;
try
ts.Add('XML=' + AXMLDoc.XML.Text));
HTTPString := IdHTTPClient.Post('http://' + FHost + ':' + IntToStr(FPort) + FHttpRoot, ts);
finally
ts.Free;
end;
My XML file is UTF-8 encoded.
What I have to do get good encoding on my server (I also use Indy for server) ?
UTF-8 is the default charset that TIdHTTP
uses for submitting a TStringList
object. The real issue is that XML should not be submitted using a TStringList
to begin with, even with a proper charset. The reason is because the TIdHTTP.Post(TStrings)
method implements the application/x-www-form-urlencoded
content type, and thus url-encodes the TStringList
content, which can break XML if the receiver is not expecting that. So unless the receiver is actually expecting a real application/x-www-form-urlencoded
encoded request, XML should be transmitted using the TIdHTTP.Post(TStream)
method instead so the raw XML bytes are preserved as-is.