Tôi gặp sự cố với phương pháp Indy IdHttp Post. Chức năng CallRpc() được biên dịch với Delphi 2007 hoạt động tốt nhưng cùng một mã được biên dịch với Delphi 2010 làm tăng ngoại lệ.Sự cố với Indy IdHttp Post in Delphi 2010
Tôi phải xem xét điều gì khi tôi thay đổi Delphi 2007 Indy TIdHttp sang 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;
Addition 2009/01/25:
ngoại lệ là thế này: EIdConnClosedGracefully
đáp ứng là:
<?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>
Solution 2009/01/26:
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;
kết thúc;
Chào mừng bạn đến với Stack Overflow. Hãy nhớ bao gồm các chi tiết nổi bật như ** mà ** ngoại trừ bạn nhận được để người đọc không phải đoán. –
Tôi sẽ bao gồm thêm chi tiết khi tôi có thể sử dụng lại máy tính mã hóa của mình và lặp lại lỗi. – pKarelian