Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdHTTP corrections when proxy is used
#8
(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;

Reply


Messages In This Thread
IdHTTP corrections when proxy is used - by NevTon - 04-29-2019, 01:17 PM
RE: IdHTTP corrections when proxy is used - by rlebeau - 05-10-2019, 07:23 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)