Solved

Working with Internet behind proxy

Posted on 2003-12-02
9
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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