I need help with a component I have taken over as a new employee with the task of adding new methods to the component. The component uses idTCPClient and NOT idHTTP. See the responses in the two questions below for the reasons why.
Getting XML from response stream using Indy's IDTCPClient
Getting HTML from response stream using Indy's IDTCPClient
Yes Remy & Jerry, I have begun the rewrite of the component to utilize tidHTTP instead of idTCPClient, but I am doing it on my own free time, not the companies time. SO, I will need to finish it tonight. Ok, back to this post.
Calling the get function below, I get the following response back
HTTP/1.0 200 OK
Content-Length: 2069
Date: Wed, 20 Nov 2013 15:00:11 GMT
Content-Type: text/xml; charset=UTF-8
function TMyConnector.GET(aRawHeader: String): String;
begin
if Not Connected then Connected := True;
if Connected then
begin
FRawRequest := 'GET /'+ EncodeUrl(aRawHeader) + ' HTTP/'+HTTPVerText+#13#10+
'Host: '+FHost+#13#10+
'Cookie: UserHPos=IOGLO00003000090000C000BS; '+
'LOSID=qsBiy/wEDCq6tOXFzGbOlTD1lmo5AXdFnCkbzzPn6+qCeheYVyTcumRrjsqh+Hds4Fr2gZDazfDzGN1RA+nnHuQQeBy78ZUgctrZyyy9MnGl2qI/ulkV6EPxAfmmLg/lopRq99f5gAcG/dgtytAJjS+aD5DqtHGrAqjiqgtkwuA=; '+
'LoginHPos=IOGLO00003000090000C000BS; '+
'UIHPos=IOGLO00003000020000500003; '+
'LOSG=61939308-7C83-47ED-B909-2D2D10AD7026; '+
'fControllingBusiness=IOGLO000030000900001000050000200001'+#13#10+
'Connection: Close'+#13#10+
#13#10;
FSock.Socket.Write(FRawRequest);
FRawResponse := FSock.Socket.ReadLn(#13#10#13#10,nil);
Result := FRawResponse;
if ResponseStream = nil then ResponseStream := TMemoryStream.Create
else ResponseStream.SetSize(0);
FSock.Socket.ReadStream(ResponseStream,-1,True);
if Connected and (Not KeepAlive) then Connected := False;
end;
end;
How do I now get the XML string from responseStream?
There is a current method that already exist for JSON
Procedure TMyConnector.GenerateJSON;
begin
if ResponseStream <> nil then
Begin
ResponseJSON_V := TJSONObject.ParseJSONValue(StreamToArray(ResponseStream),0) as TJSONValue;
End;
end;
I would like to create a method for XML, and I tried the following:
Procedure TMyConnector.GenerateXML;
var
S: String;
begin
if ResponseStream <> nil then
// code here to convert ResponseStream to XML
ResponseXML_v:= S;
end;