We help IT Professionals succeed at work.

detect the proxy adrress and port at the run time

vinch81
vinch81 asked
on
920 Views
Last Modified: 2010-04-05
hi all,

im using idHttp to get a file from the internet. Im using proxy server... so, i have to request from proxy address before I send the get request.

here is my code :
    IdHTTP1.Request.ProxyServer := ProxyAddress;
    IdHttp1.Request.ProxyPort := ProxyPort;
    HTMLContent := IdHTTP1.Get(IEAddress);

my question is, can I detect the proxy address and the port automatically at the run time ? so that the user doest need to key in the address and the port number ?

thanks :D
Comment
Watch Question

Commented:
You can read the Proxy settings from IE using, But u need 'winhttp.dll'
For more help search "WinHttpGetIEProxyConfigForCurrentUser" in MSDN online

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls;

type

  PWinHttpCurrentUserIeProxyConfig = ^TWinHttpCurrentUserIeProxyConfig;

  TWinHttpCurrentUserIeProxyConfig = record
    fAutoDetect : boolean;
    lpszAutoConfigUrl : PWideChar;
    lpszProxy : PWideChar;
    lpszProxyBypass : PWideChar;
  end;
  TWinHttpGetIeProxyConfigForCurrentUser = function (pProxyConfig : PWinHttpCurrentUserIeProxyConfig) : boolean; stdcall;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  WinHttpGetIeProxyConfigForCurrentUser : TWinHttpGetIeProxyConfigForCurrentUser;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  H: THandle;
  Config: TWinHttpCurrentUserIeProxyConfig;
begin
  H := LoadLibrary ('winhttp.dll');
  if H <> 0 then
  try
    @WinHttpGetIeProxyConfigForCurrentUser := GetProcAddress (H, 'WinHttpGetIEProxyConfigForCurrentUser');
    if Assigned (WinHttpGetIeProxyConfigForCurrentUser) then
      WinHttpGetIeProxyConfigForCurrentUser(@Config);
    ShowMEssage(Config.lpszProxy);
  finally
    FreeLibrary (H);
  end;
end;

end.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
whoa.. what a big procedure there =p
okay, i think im going to try the second one first :D
anyway, i tried to use that but didn't work...

what should I put in the top uses list .?
i tried to put " registery " there. it wont run, it give me error : file not found : registry.dcu

humm... how can I solve this ?

thank yahh ^^

Commented:
For second one

uses registry in the uses clause,

It should work

You have used registery but it is registry

please try once more

Author

Commented:
ooppppssss okok i'll try again than :D

Author

Commented:
okayyy it's work just fine ;);)
thanks alot....

btw, if I run this procedure in the computer without proxy connection... what value will I get .??

Commented:
You will not have any value in it

Author

Commented:
okayy... Thanks alot for your help ;)

Author

Commented:
uhmmm just courious, is there any way that I can manually open the registry file ?
cos I know nothing abt this and I have to write abt this =p
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.