Link to home
Start Free TrialLog in
Avatar of lamtl354
lamtl354Flag for Hong Kong

asked on

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;

#########################################
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lamtl354

ASKER

hi geobul,

could you tell me how to set these setting?
thx
Avatar of geobul
geobul

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
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?
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
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
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?
Ooppps, My bad, Didnt see that post.

I will leave the following recommendation for this question in the Cleanup topic area:
Accept: geobul