Solved

Working with Internet behind proxy

Posted on 2003-12-02
9
285 Views
Last Modified: 2010-04-05
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;

#########################################
0
Comment
Question by:lamtl354
  • 4
  • 2
  • 2
9 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 9865166
Hi,

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

Regards, Geo
0
 

Author Comment

by:lamtl354
ID: 9871209
hi geobul,

could you tell me how to set these setting?
thx
0
 
LVL 17

Expert Comment

by:geobul
ID: 9874764
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
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:lamtl354
ID: 9879583
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?
0
 
LVL 17

Expert Comment

by:geobul
ID: 9881054
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
0
 
LVL 2

Expert Comment

by:-Karamja-
ID: 12382303
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
0
 
LVL 17

Expert Comment

by:geobul
ID: 12382947
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?
0
 
LVL 2

Expert Comment

by:-Karamja-
ID: 12383023
Ooppps, My bad, Didnt see that post.

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now