Working with Internet behind proxy

hi all,

i am writing a program to retrieve contents of web page, but
fail when i read() the URL(http://www.yahoo.com)
the developemnt environment is behind proxy server. anything wrong?

#########################################

procedure TWeb.GrabHtml;
var
  Http1: TIdHttp;
  strUrl: String;
begin
  strUrl := 'http://www.yahoo.com';
  Status := 'Sending query: ' + StrUrl;
  Synchronize (ShowStatus);
  Http1 := TIdHttp.Create(nil);
  try
    Http1.Request.UserAgent := 'User-Agent: NULL';
    Http1.OnWork := HttpWork;
    strRead := Http1.Get(strUrl);
  finally
    Http1.Free;
  end;
end;

#########################################
lamtl354Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hi,

You have to set ProxyParams property of your Http1 (ProxyServer and ProxyPort at least and others if your proxy requires authentication).

Regards, Geo

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lamtl354Author Commented:
hi geobul,

could you tell me how to set these setting?
thx
geobulCommented:
Hi,

This way:

...
  Http1 := TIdHttp.Create(nil);
  try
// new code
   with Http1.ProxyParams do begin
    // at least
    ProxyServer := '127.0.0.1'; // the ip address of your proxy - string
    ProxyPort := 80; // your proxy port - integer
    // if your proxy requires authentication
    ProxyUsername := 'user';
    ProxyPassword := 'password';
    // and perhaps
    BasicAuthentication := true;
  end;
// your code continues
  Http1.Request.UserAgent := 'User-Agent: NULL';
  ...

Regards, Geo
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

lamtl354Author Commented:
if i didn't know the proxy setting, how could we do this?
can the applicartion detect proxy setting from somewhere just like what IE do?
geobulCommented:
It would be a lot easier if you use the following. You don't have to bother yourself whether there is a proxy or not. If IE works on a computer then this code will work also.

uses URLMon;

procedure TWeb.GrabHtml;
var
  strUrl: String;
  LocalFile: string;
begin
  strUrl := 'http://www.yahoo.com';
  LocalFile := 'c:\yahoo.html';

  if URLDownloadToFile(nil, PChar(strUrl), PChar(LocalFile), 0, nil) <> 0 then
    MessageBox(0, 'Cannot download the file.', PChar(Application.Title), MB_ICONERROR or MB_OK);
end;

Regards, Geo
-Karamja-Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
PAQ - Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Karamja (Alan)
EE Cleanup Volunteer
geobulCommented:
Why? I think I've answered the question: how to set up proxy settings using Indy's TIdHTTP component. There was a follow-up question also answered by me. What else should I have done?
-Karamja-Commented:
Ooppps, My bad, Didnt see that post.

I will leave the following recommendation for this question in the Cleanup topic area:
Accept: geobul
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.