Problema com o Indy IdHttp Post no Delphi 2010
Estou com um problema com o método Indy IdHttp Post. A função CallRpc () compilada com o Delphi 2007 funciona bem, mas o mesmo código compilado com o Delphi 2010 gera exceção.
O que devo considerar ao mudar o Delphi 2007 Indy TIdHttp para Delphi 2010 Indy TIdHttp?
function CallRpc(const sURL, sXML: string): string;
var
SendStream : TStream;
IdHttp : TIdHttp;
begin
SendStream := TMemoryStream.Create;
IdHttp := TIdHttp.Create(nil);
try
IdHttp.Request.Accept := '*/*';
IdHttp.Request.ContentType := 'text/sXML';
IdHttp.Request.Connection := 'Keep-Alive';
IdHttp.Request.ContentLength := Length(sXML);
StringToStream(sXML, SendStream);
SendStream.Position := 0;
Result := IdHttp.Post(sURL, SendStream);
finally
IdHttp.Free;
SendStream.Free;
end;
end;
Adição 25.1.2009:
A exceção é esta: EIdConnClosedGracfully
A resposta é esta:
<?xml version='1.0' encoding='us-ascii'?>
<!DOCTYPE Error [ <!ELEMENT Error (ErrorMessage,DebuggingInfo*)> <!ATTLIST Error Date CDATA #REQUIRED Time CDATA #REQUIRED> <!ELEMENT ErrorMessage (#PCDATA )> <!ELEMENT DebuggingInfo (#PCDATA )> ] >
<Error Date='01/25/2010' Time='08:57:12'>
<ErrorMessage>
XML SERVER ERROR: There was a SYSTEM ERROR error in the Incoming XML Response: $ZE=<UNDEFINED>lexan+196^%eXMLLexAnalyzer
</ErrorMessage>
Solução 26.1.2009:
function CallRpc(const sURL, sXML: string): string;
var
SendStream : TStream;
IdHttp : TIdHttp;
sAnsiXML: Ansistring; // <-- new
begin
sAnsiXML := sXML; // <-- new: Implicit string cast
SendStream := TMemoryStream.Create;
IdHttp := TIdHttp.Create(nil);
try
IdHttp.Request.Accept := '*/*';
IdHttp.Request.ContentType := 'text/sXML';
IdHttp.Request.Connection := 'Keep-Alive';
IdHttp.Request.ContentLength := Length(sAnsiXML); // <-- new
SendStream.Write(sAnsiXML[1], Length(sAnsiXML)); // <-- new
SendStream.Position := 0;
Result := IdHttp.Post(sURL, SendStream);
finally
IdHttp.Free;
SendStream.Free;
end;
fim;