Indy IdHttp发布在Delphi 2010中的问题 [英] Problem with Indy IdHttp Post in Delphi 2010

查看:122
本文介绍了Indy IdHttp发布在Delphi 2010中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Indy IdHttp Post方法的问题。
使用Delphi 2007编译的函数CallRpc()工作正常,但使用Delphi 2010编译的相同代码引发异常。



当我更改Delphi 2007时需要考虑什么Indy TIdHttp到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;

结果:= IdHttp.Post(sURL,SendStream);
finally
IdHttp.Free;
SendStream.Free;
结束
结束

加法25.1.2009:



异常是这样的:EIdConnClosedGracefully



回复是这样的:

  xml version ='1.0'encoding ='us-ascii'?> 
<!DOCTYPE错误[<!ELEMENT Error(ErrorMessage,DebuggingInfo *)> <!ATTLIST错误日期CDATA #REQUIRED时间CDATA#REQUIRED> <!ELEMENT ErrorMessage(#PCDATA)> <!ELEMENT DebuggingInfo(#PCDATA)> ]
< Error Date = '01 / 25/2010'Time = '08:57:12'>
< ErrorMessage>
XML SERVER ERROR:传入XML响应中出现SYSTEM ERROR错误:$ ZE =& lt; UNDEFINED& gt; lexan + 196 ^%eXMLLexAnalyzer
< / ErrorMessage>



解决方案26.1.2009: / p>

  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;

结果:= IdHttp.Post(sURL,SendStream);
finally
IdHttp.Free;
SendStream.Free;
结束

end;

解决方案

查看是否使sXML ansistring有所作为。



该字符串以UTF-16等级流式传输。


I have problem with Indy IdHttp Post method. Function CallRpc() compiled with Delphi 2007 works fine but same code compiled with Delphi 2010 raises exception.

What do I have to consider when I change Delphi 2007 Indy TIdHttp to 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 25.1.2009:

Exception is this: EIdConnClosedGracefully

Response is this:

<?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=&lt;UNDEFINED&gt;lexan+196^%eXMLLexAnalyzer
</ErrorMessage>

Solution 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; 

end;

解决方案

see if making sXML ansistring makes a difference.

Maybe the string is streamed in UTF-16 or so.

这篇关于Indy IdHttp发布在Delphi 2010中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆