Board index » delphi » TidHTTP and PROXY

TidHTTP and PROXY

Im using idHTTP to download a file from internet and it is working fine, but i dont know how do this through a PROXY server. If anyone knows how to do this, please post a message, I will be grateful!

Best regards,
Bojidar

 

Re:TidHTTP and PROXY


I tried with ProxyParams but im still receiving "Host not found"
The proxy server does not require authentication.

Here's the code:

procedure TProcess.GetFile;
var Source :TStream;
    Stream :TMemoryStream;
    HTTP   :TidHTTP;
    err    :boolean;
begin
  Source := TStream.Create;
  Stream := TMemoryStream.Create;
  HTTP:= TidHTTP.Create(nil);
  HTTP.ProxyParams.ProxyServer := '192.168.0.1';
  HTTP.ProxyParams.ProxyPort := 3128;
  HTTP.Host := 'whatever host';
  try
    with HTTP do begin
      Connect;
      DoRequest(hmGet, 'http://decart.hit.bg/top.html',Source,Stream);
    end;
    Stream.SaveToFile('d:\temp.tmp');
  except
    on exception: exception
      do begin
        MessageBox(0,PChar(exception.message),'Exception!',0);
        err := true;
    end;
  end;
  HTTP.Free;
  Source.Free;
  Stream.Free;
  if not err then
    MessageBox(0,PChar('Finnished'),'Status Message',0);
end;

Re:TidHTTP and PROXY


Quote
Bojidar Markov wrote:
> Im using idHTTP to download a file from internet and it is working fine, but i dont know how do this through a PROXY server. If anyone knows how to do this, please post a message, I will be grateful!

> Best regards,
> Bojidar

Look at the ProxyParams property.  Setting it up is as easy as this:

   HTTP.ProxyParams.ProxyServer := edtServer.Text;
   HTTP.ProxyParams.ProxyPort := StrToInt(edtPort.Text);

If your proxy requires authentication:

   HTTP.ProxyParams.BasicAuthentication := False;
   HTTP.ProxyParams.ProxyUsername := edtUser.Text;
   HTTP.ProxyParams.ProxyPassword := edtPassword;

Regards,
Bruce McGee
Glooscap Software

Re:TidHTTP and PROXY


i doubt that the IP ur using is correct.
Quote
Bojidar Markov wrote:
> I tried with ProxyParams but im still receiving "Host not found"
> The proxy server does not require authentication.

> Here's the code:

> procedure TProcess.GetFile;
> var Source :TStream;
>     Stream :TMemoryStream;
>     HTTP   :TidHTTP;
>     err    :boolean;
> begin
>   Source := TStream.Create;
>   Stream := TMemoryStream.Create;
>   HTTP:= TidHTTP.Create(nil);
>   HTTP.ProxyParams.ProxyServer := '192.168.0.1';
>   HTTP.ProxyParams.ProxyPort := 3128;
>   HTTP.Host := 'whatever host';
>   try
>     with HTTP do begin
>       Connect;
>       DoRequest(hmGet, 'http://decart.hit.bg/top.html',Source,Stream);
>     end;
>     Stream.SaveToFile('d:\temp.tmp');
>   except
>     on exception: exception
>       do begin
>         MessageBox(0,PChar(exception.message),'Exception!',0);
>         err := true;
>     end;
>   end;
>   HTTP.Free;
>   Source.Free;
>   Stream.Free;
>   if not err then
>     MessageBox(0,PChar('Finnished'),'Status Message',0);
> end;

Re:TidHTTP and PROXY


I can't guarantee this is the best way, but here's a little bit more
streamlined example.  I pretty much just use Get and Post.

var
   HTTP   :TidHTTP;
   Stream :TMemoryStream;
begin
   Stream := TMemoryStream.Create;
   HTTP:= TidHTTP.Create(nil);
   try
     HTTP.ProxyParams.ProxyServer := '192.168.0.1';
     HTTP.ProxyParams.ProxyPort := 3128;
     try
       HTTP.Get('http://www.borland.com', Stream);
       Stream.SaveToFile('d:\temp.tmp');
       MessageBox(0,PChar('Finished'),'Status Message',0);
     except
       on exception: exception do
         MessageBox(0,PChar(exception.message),'Exception!',0);
     end;
   finally
     HTTP.Free;
     Stream.Free;
   end;

Regards,
Bruce McGee
Glooscap Software

Re:TidHTTP and PROXY


For testing, I use several from the lists:
http://www.publicproxyservers.com

Quote
"Bojidar Markov" <bojidarmar...@mail.bg> wrote in message

news:3edf51ff$1@newsgroups.borland.com...
Quote

> Im using idHTTP to download a file from internet and it is working fine,

but i dont know how do this through a PROXY server. If anyone knows how to
do this, please post a message, I will be grateful!
Quote

> Best regards,
> Bojidar

Re:TidHTTP and PROXY


Thanks for the working example ;)

Quote
"Bruce McGee" <bmc...@ionline.net> wrote in message

news:3edf6e3f$1@newsgroups.borland.com...
Quote
> I can't guarantee this is the best way, but here's a little bit more
> streamlined example.  I pretty much just use Get and Post.

> var
>    HTTP   :TidHTTP;
>    Stream :TMemoryStream;
> begin
>    Stream := TMemoryStream.Create;
>    HTTP:= TidHTTP.Create(nil);
>    try
>      HTTP.ProxyParams.ProxyServer := '192.168.0.1';
>      HTTP.ProxyParams.ProxyPort := 3128;
>      try
>        HTTP.Get('http://www.borland.com', Stream);
>        Stream.SaveToFile('d:\temp.tmp');
>        MessageBox(0,PChar('Finished'),'Status Message',0);
>      except
>        on exception: exception do
>          MessageBox(0,PChar(exception.message),'Exception!',0);
>      end;
>    finally
>      HTTP.Free;
>      Stream.Free;
>    end;

> Regards,
> Bruce McGee
> Glooscap Software

Re:TidHTTP and PROXY


Hi Darron,

Good infomration about public proxy servers, is there a proxy that requires
user name and password? I only want to test my program with user name and
password on.

Thanks,

Frank

Quote
"Daaron" <ddw...@starband.net> wrote in message

news:3edfb4b7$1@newsgroups.borland.com...
Quote
> For testing, I use several from the lists:
> http://www.publicproxyservers.com

> "Bojidar Markov" <bojidarmar...@mail.bg> wrote in message
> news:3edf51ff$1@newsgroups.borland.com...

> > Im using idHTTP to download a file from internet and it is working fine,
> but i dont know how do this through a PROXY server. If anyone knows how to
> do this, please post a message, I will be grateful!

> > Best regards,
> > Bojidar

Other Threads