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;
开发者_StackOverflow社区 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.
on the DFM, I set under idHTTP1 the compressor, CookieManager, Intercept, and IOHandler. I copies the required OpenSSL dll files to the project folder
Keep getting the error: Failed to parse XML-RPC request: XML document structures must start and end within the same entity
Any ideas on how to fix this?
that's an xml parser exception, probably thrown server-side.
as the xml you're sending is valid (however you really should be using an xml library to build it!), the error most likely means that the stream the server is receiving is being truncated... in other words the content-length header is less than the bytes sent.
my guess is as you're using a unicode enabled version of delphi, your content-length will be set to half of the actual bytes sent; change the datatype of Text
in StringToStream
to AnsiString
.
or ... Stream.Write(Text[1], (Length(Text) * SizeOf(Char))); ... temp:= '... encoding="UTF-16"?>
精彩评论