Solved

Delphi HTTP Examples for Client - Server using domain name

Posted on 2010-08-19
8
1,232 Views
Last Modified: 2013-11-23
I would like to retrieve files from a server using HTTP. No password rigt now, but will have do use on soon.  I would also like to be able to view directories on the server and delete files (with permission). I would also like to be able to send the server HTTP commands and parse results as a learning exercise.

I have the Indy Components and they look very powerful. I have tried their Client example to connect to a host without success. Probably because I am using a domain name instead of the IP adress (which I do not have). Not sure if this is the best approach to my problem.

0
Comment
Question by:magman5
8 Comments
 
LVL 13

Expert Comment

by:aflarin
ID: 33482469
0
 
LVL 8

Expert Comment

by:GeneralTackett
ID: 33489567
Is writing an ISAPI dll within the realm of what you can do?  If so I have examples that do just what you want.
0
 
LVL 14

Expert Comment

by:systan
ID: 33536165
hi Aflarin;
Is that Ok for ciuly?
0
 

Author Comment

by:magman5
ID: 33554730
thanks aflarin
most useful (in future), however I do not have control of the server. I just want to send it HTTP commands.

GeneralTackett
thanks for the suggestion. I have no idea what ISAPI is - can you point me in the direction of some good explanations so I can consider your suggestion.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:aflarin
ID: 33556219
hi Systan. why not?

@magman5
>> I just want to send it HTTP commands.

Here is sending Get command to get html and files:

uses
  IdHttp;

function HTTPGet( const URL: string ): string;
var
  IdHTTP1: TIdHTTP;
begin
  IdHTTP1:= TIdHTTP.Create(nil);
  try
    IdHTTP1.HandleRedirects := True;
    Result:= IdHTTP1.Get( URL );
  finally
    IdHTTP1.Free;
  end;
end;

procedure HTTPGetFile( const URL, FileName: string );
var
  IdHTTP1: TIdHTTP;
  fs: TFileStream;
begin
  IdHTTP1:= TIdHTTP.Create(nil);
  try
    IdHTTP1.HandleRedirects := True;

    fs:= TFileStream.Create(FileName, fmCreate );
    try
      IdHTTP1.Get( URL, fs );
    finally
      fs.Free;
    end;

  finally
    IdHTTP1.Free;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Text:= HTTPGet( 'http://google.com' );
  HTTPGetFile( 'http://download.thinkbroadband.com/5MB.zip', 'c:\test.zip' );
end;
0
 

Author Comment

by:magman5
ID: 33564803
Thanks aflarin

HTTPgetfile works well.

Any suggestions for using other HTTP commands ?
0
 
LVL 13

Accepted Solution

by:
aflarin earned 125 total points
ID: 33564851
TidHTTP component has Post, Get, Trace and Head methods to appropriate HTML commands.

Also it has universal DoRequest method for all HTML commands

procedure DoRequest(const AMethod: TIdHTTPMethod; AURL: string; const ASource: TStream; const AResponseContent: TStream); virtual;

where TIdHTTPMethod is

TIdHTTPMethod = (hmHead, hmGet, hmPost, hmOptions, hmTrace, hmPut, hmDelete, hmConnect);
0
 

Author Closing Comment

by:magman5
ID: 33564916
many thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 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

24 Experts available now in Live!

Get 1:1 Help Now