05-10-2019, 07:23 PM
(05-09-2019, 07:44 AM)NevTon Wrote: I do not have a way to test, if this will be filled with some data, as I do not have administrative privilege to the proxy.
You do not actually need a live proxy or a live webserver in order to test how TIdHTTP parses response data. You can make use of Indy's TIdIOHandlerStream component to feed in your own test data directly into TIdHTTP without using a TCP socket at all. For example:
Code:
var
ServerData: TStringStream;
//ClientData: TStreamStream;
IO: TIdIOHandlerStream;
begin
ServerData := TStringStream.Create(
'HTTP/1.1 407 Proxy Authentication Required' + EOL +
'Proxy-Authenticate: Basic realm="test"' + EOL +
'Content-Length: 28' + EOL +
EOL +
'Proxy credentials are needed' +
'HTTP/1.1 200 OK' + EOL +
'Content-Type: text/plain' + EOL +
'Content-Length: 8' + EOL +
EOL +
'Success!'
, TEncoding.UTF8);
try
// optional: if you want to see what TIdHTTP "sends", you can
// also assign a separate TStream to receive the sent data...
{ClientData := TStreamStream.Create('', TEncoding.UTF8);
try}
IO := TIdIOHandlerStream.Create(IdHTTP, ServerData{, ClientData});
IO.FreeStreams := False;
IdHTTP1.IOHandler := IO;
IdHTTP1.ProxyParams.ProxyServer := 'testproxy';
IdHTTP1.ProxyParams.ProxyPort := 8080;
ShowMessage(IdHTTP1.Get('http://dummy.com'));
{finally
//ShowMessage(ClientData.DataString);
ClientData.Free;
end;}
finally
ServerData.Free;
end;
end;