加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi 2010中Indy IdHttp Post的问题

发布时间:2020-12-15 09:27:32 所属栏目:大数据 来源:网络整理
导读:我有Indy IdHttp Post方法的问题. 使用Delphi 2007编译的函数CallRpc()工作正常,但使用Delphi 2010编译的相同代码引发了异常. 当我将Delphi 2007 Indy TIdHttp更改为Delphi 2010 Indy TIdHttp时,我需要考虑什么? function CallRpc(const sURL,sXML: string)
我有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;

      Result := IdHttp.Post(sURL,SendStream);
  finally
    IdHttp.Free;
    SendStream.Free;
  end;
end;

增加25.1.2009:

例外是:EIdConnClosedGracefully

回应是这样的:

<?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>

解决方案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;

结束;

解决方法

看看制作sXML ansistring是否有所作为.

也许字符串以UTF-16流式传输.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读