views:

246

answers:

2
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.

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?

+1  A: 

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.

glob
That worked! :P Any suggestions on a easy to use xml library that is compatible with Lazarus also?
Brad
Ended up using OmniXML for an XML library
Brad
A: 

or ... Stream.Write(Text[1], (Length(Text) * SizeOf(Char))); ... temp:= '... encoding="UTF-16"?>

Rada
Welcome to Stack Overflow. What was the leading "or" referring to? Please don't assume that people have read all the other answers before reading yours. By default, Stack Overflow displays answers ranked by total votes, so ordering can change as people vote on them. Answers with an equal number of votes are displayed in random order. Also, answers with code do better when there is *text* in them explaining what the code is doing and why it's important.
Rob Kennedy