【发布时间】:2010-09-02 03:27:28
【问题描述】:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack,
IdIntercept, IdCookieManager, IdZLibCompressorBase, IdCompressorZLib, IdSSL,
IdSSLOpenSSL;
type
TForm2 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
IdCompressorZLib1: TIdCompressorZLib;
IdCookieManager1: TIdCookieManager;
IdConnectionIntercept1: TIdConnectionIntercept;
IdIOHandlerStack1: TIdIOHandlerStack;
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure StringToStream(const Text: string; Stream: TStream);
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.StringToStream(const Text: string; Stream: TStream);
begin
Stream.Write(Text[1], Length(Text));
end;
procedure TForm2.Button1Click(Sender: TObject);
var
temp:string;
SendStream: TStream;
ResponseStream: TStream;
begin
SendStream := TMemoryStream.Create;
ResponseStream := TMemoryStream.Create;
temp:= '<?xml version="1.0"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
<param>
<value>%WEBNAME%</value>
</param>
<param>
<value>%WEBADDREESS%</value>
</param>
</params>
</methodCall>'; // copied from text file where I was loading this
temp:= StringReplace(temp, '%WEBNAME%', 'Generic Website Title',[rfReplaceAll, rfIgnoreCase]);
temp:= StringReplace(temp, '%WEBADDREESS%', 'http://www.testingwebsite.com',[rfReplaceAll, rfIgnoreCase]);
memo1.Lines.Add(temp);
StringToStream(temp, SendStream); // convert to a stream
SendStream.Position := 0;
idhttp1.Request.Accept := '*/*';
idhttp1.Request.ContentType := 'text/xml';
idhttp1.Request.Connection := 'Keep-Alive';
idhttp1.Request.ContentLength := Length(temp);
memo1.lines.Add(idhttp1.Post('http://ping.feedburner.com', SendStream));
{
if FHostPort = 80 then
Session.Post('http://' + FHostName + FEndPoint, SendStream,
ResponseStream)
else
Session.Post('http://' + FHostName + ':' + IntToStr(FHostPort) +
FEndPoint, SendStream, ResponseStream);
if FSSLEnable then
Session.Post('https://' + FHostName + ':' + IntToStr(FHostPort) +
FEndPoint, SendStream, ResponseStream);
}
end;
end.
在 DFM 上,我在 idHTTP1 下设置了压缩器、CookieManager、Intercept 和 IOHandler。 我将所需的 OpenSSL dll 文件复制到项目文件夹中
不断收到错误: 解析 XML-RPC 请求失败:XML 文档结构必须在同一实体内开始和结束
关于如何解决这个问题的任何想法?
【问题讨论】:
-
你从哪里得到这个错误?如果是 Delphi 异常,谁提出来? (启用“调试 DCU”并查看调试器中的调用堆栈。)您确定这真的是 Delphi 问题吗?如果您使用 wget 或 curl 命令行程序发布相同的请求会怎样?
-
您确定 '%WEBNAME%' 和 '%WEBADDREESS%' 变量的实际值没有无效的 XML 字符吗?你在编码这些值吗?
标签: delphi delphi-2009 delphi-2010 xml-rpc