I have a component that a previous employee has created. It uses Indy (IDTCPClient) and the following method to perform requests (Where "aReadHeader" is a predefined Uri built before being passed in).
function TMyConnector.GET(aRawHeader: String): String;
begin
if Not Connected then Connected := True;
if Connected then
begin
FRawRequest := 'GET /'+ 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;
Question the FRawResponse returns
HTTP/1.0 200 OK Content-Length: 5560 Date: Mon, 18 Nov 2013 15:05:07 GMT Content-Type: text/html; charset=UTF-8 ...,public
How can I actually get this html content from ResponseStream to HTML
One of the methods which currently exists is "GenerateJSON" (see code below). I would like to create one called "GenerateHTML"
Function StreamToArray(Strm:TStream):TArray<Byte>;
Begin
Strm.Position := 0;
SetLength(Result,Strm.Size);
Strm.Read(Result[0],Strm.Size);
End;
Procedure TMyConnector.GenerateJSON;
begin
if ResponseStream <> nil then
Begin
ResponseJSON_V := TJSONObject.ParseJSONValue(StreamToArray(ResponseStream),0) as TJSONValue; // Note ResponseJSON_V is declared as TJSONValue in TMyConnector);
End;
end;
so, I would need
Procedure TMyConnector.GenerateHTML;
begin
if ResponseStream <> nil then
Begin
// result:= html from stream here
End;
end;
EDIT:
Procedure TMyConnector.GenerateXML;
var
S: String;
begin
if ResponseStream <> nil then
Begin
try
while FSock.IOHandler.CheckForDataOnSource(30) do
begin
S := FSock.IOHandler.InputBufferAsString;
end;
finally
ResponseStr_v:= S;
end;
End;
end;