IdHttp Post Method Delphi 2010
Posted
by Dusten S
on Stack Overflow
See other posts from Stack Overflow
or by Dusten S
Published on 2010-05-25T21:17:17Z
Indexed on
2010/05/25
21:21 UTC
Read the original article
Hit count: 919
delphi-2010
|indy10
Like others before me, I'm having troubles using the IdHttp(Indy 10.5.5) component in Delphi 2010. The code works fine in Delphi 7:
var
XMLString : AnsiString;
lService : AnsiString;
ResponseStream: TMemoryStream;
InputStringList : TStringList;
begin
ResponseStream := TMemoryStream.Create;
InputStringList := TStringList.Create;
XMLString :='<?xml version="1.0" encoding="ISO-8859-1"?> '+
'<!DOCTYPE pnet_imessage_send PUBLIC "-//PeopleNet//pnet_imessage_send" "http://open.peoplenetonline.com/dtd/pnet_imessage_send.dtd"> '+
'<pnet_imessage_send> '+
' <cid>username</cid> '+
' <pw>password</pw> '+
' <vehicle_number>tr01</vehicle_number> '+
' <deliver>now</deliver> '+
' <action> '+
' <action_type>reply_with_freeform</action_type> '+
' <urgent_reply>yes</urgent_reply> '+
' </action> '+
' <freeform_message>Test Message Version 2</freeform_message> '+
'</pnet_imessage_send> ';
lService := 'imessage_send';
InputStringList.Values['service'] := lService;
InputStringList.Values['xml'] := XMLString;
try
IdHttp1.Request.Accept := '*/*';
IdHttp1.Request.ContentType := 'text/XML';
IdHTTP1.Post('http://open.peoplenetonline.com/scripts/open.dll', InputStringList, ResponseStream);
...
finally
ResponseStream.Free;
InputStringList.Free;
end;
The only differences so far between this and the D7 code is that I've changed the String types to AnsiString, and added the HTTP Request properties.
The response I get back from the server is 'XML failed to parse. Whitespace expected at Line:1 Position: 19', I'm assuming the XML got garbled up somewhere in the process, but I can't figure our where I'm going wrong.
Any ideas?
© Stack Overflow or respective owner